0
我嘗試通過嵌套指令循環一個函數。從console.info
在myCtrl
我期望字符串"this should be logged"
。通過嵌套指令循環功能 - angularjs
angular.module('myApp')
.controller('myCtrl', function ($scope) {
$scope.aFunction = function(input) {
console.info(input.message);
}
})
.directive('levelOneDirective', function() {
return {
templateUrl: '<level-two-directive aFunction="aFunction(object)"></level-two-directive>',
restrict: 'EA',
scope: {
aFunction:"&"
},
link: function (scope, element, attrs) {
}
};
})
.directive('levelTwoDirective', function() {
return {
templateUrl: '<div ng-click="aFunction({message: 'this should be logged'})"></div>',
restrict: 'EA',
scope: {
aFunction:"&"
},
link: function (scope, element, attrs) {
}
};
});
在我index.html
我有類似:
<div ng-controller="myCtrl">
<level-one-directive aFunction="aFunction(object)"></level-one-directive>
</div>
但控制檯說:undefined
。
如何通過嵌套指令連接一個函數?
我有這個想法從這裏:https://egghead.io/lessons/angularjs-isolate-scope-expression-binding 很好,謝謝。它的工作。對不起,對錯。 – Stefan