Angularjs 指令内的角度调用函数 .directive('optionFoundAddressClickableDisplay',函数(搜索、$state、服务、$log){ "严格使用",; 返回{ 替换:正确, 限制:“AE”, 模板:''+ “”, 链接:函数(范围、元素、属性){ scope.buildingName=search.result.buildingAddress; scope.barClickable=(search.result.matchedNua | | | search.result.matchedId!==null)?true:false; scope.searchMatch=函数(){ $log.warn(“到达此处”); }; } }; })

Angularjs 指令内的角度调用函数 .directive('optionFoundAddressClickableDisplay',函数(搜索、$state、服务、$log){ "严格使用",; 返回{ 替换:正确, 限制:“AE”, 模板:''+ “”, 链接:函数(范围、元素、属性){ scope.buildingName=search.result.buildingAddress; scope.barClickable=(search.result.matchedNua | | | search.result.matchedId!==null)?true:false; scope.searchMatch=函数(){ $log.warn(“到达此处”); }; } }; }),angularjs,angularjs-directive,Angularjs,Angularjs Directive,在我的指令ng click-searchMatch()中似乎无法命中函数。我是否需要以不同的方式在指令中声明函数?在指令控制器中定义它 例: .directive('optionFoundAddressClickableDisplay',函数(搜索、$state、服务、$log){ "严格使用",; 返回{ 替换:正确, 限制:“AE”, 模板:''+ “”, 链接:函数(范围、元素、属性){ scope.buildingName=search.result.buildingAddress; s

在我的指令ng click-searchMatch()中似乎无法命中函数。我是否需要以不同的方式在指令中声明函数?

在指令控制器中定义它

例:

.directive('optionFoundAddressClickableDisplay',函数(搜索、$state、服务、$log){
"严格使用",;
返回{
替换:正确,
限制:“AE”,
模板:'
  • '+ “
”, 链接:函数(范围、元素、属性){ scope.buildingName=search.result.buildingAddress; scope.barClickable=(search.result.matchedNua | | | search.result.matchedId!==null)?true:false; }, 控制器:功能($scope){ $scope.searchMatch=函数(){ $log.warn(“到达此处”); }; } }; })

这里有一个

控制台中有错误吗?
  .directive('optionFoundAddressClickableDisplay', function(search,$state,Service,$log) {
    'use strict';
    return {
      replace: true,
      restrict: 'AE',
      template: '<ul class="dropdown-menu apartment-group" ng-show="barClickable"><li><a href ng-click="searchMatch()"><span class="gr-arrow pull-right"></span>' +
      '<div class="result-text ng-binding"><img src="images/map-pin.png"  class="map-pin" alt=""/>{{ buildingName }}</div> </a>' +
      '</li></ul>',
      link: function(scope, element, attrs) {
        scope.buildingName = search.result.buildingAddress;
        scope.barClickable = (search.result.matchedNua || search.result.matchedId !== null) ? true : false;
        scope.searchMatch = function(){
          $log.warn("gets here");
        };
      }
    };
  })
.directive('optionFoundAddressClickableDisplay', function(search,$state,Service,$log) {
'use strict';
    return {
        replace: true,
        restrict: 'AE',
        template: '<ul class="dropdown-menu apartment-group" ng-show="barClickable"><li><a href ng-click="searchMatch()"><span class="gr-arrow pull-right"></span>' +
  '<div class="result-text ng-binding"><img src="images/map-pin.png"  class="map-pin" alt=""/>{{ buildingName }}</div> </a>' +
  '</li></ul>',
         link: function(scope, element, attrs) {
                   scope.buildingName = search.result.buildingAddress;
                   scope.barClickable = (search.result.matchedNua || search.result.matchedId !== null) ? true : false;
         },

         controller : function($scope) {
             $scope.searchMatch = function(){
             $log.warn("gets here");
        };
    }

 };
})