【发布时间】:2016-08-24 05:55:20
【问题描述】:
我正在创建一个小应用程序,并且我有以下带有模板的指令。
smallgrid.directive.js:
angular.module('myActions')
.directive('smallgrid', ['$rootScope', function($rootScope) {
return {
restrict: "E",
scope: {
actionable: "="
},
controller: function($scope) {
$scope.setLocation = function() {
console.log("yee");
};
}
};
}])
.directive('three', function() {
return {
replace: true,
templateUrl: '/app/my_actions/directives/templates/grid3x3.template.html'
};
})
.directive('four', function() {
return {
replace: true,
templateUrl: '/app/my_actions/directives/templates/grid4x4.template.html'
};
})
.directive('five', function() {
return {
replace: true,
templateUrl: '/app/my_actions/directives/templates/grid5x5.template.html'
};
});
grid3x3.template.html
<div class="k-edit-field" id="board">
<div class="row" ng-click="setLocation()">
{{actionable.probability}}
</div>
</div>
我使用这个指令如下:
<smallgrid three actionable="currentAction.actionable" ng-if="somecondition"></smallgrid>
UI 正确呈现。但是,它显示 {{actionable.probability}} 为空,并且 Click 事件未触发。但是,如果我删除隔离范围并直接访问变量,则值是可用的。我知道当我使用隔离作用域时,在three 指令中,我无法访问smallgrid 的值。有没有办法将这些值从 smallgrid 传递到模板?
【问题讨论】:
标签: javascript angularjs angularjs-directive angularjs-scope