我有一個控制器,並希望element.When我創建它的元素應該調用控制器函數來創建dymanically,但功能不叫AngularJs呼叫控制器功能從動態創建的元素
app.controller('AbnTestController', ['$scope','$timeout',function($scope,$timeout) {
..........................
var tree1;
tree1 = [
{
label: 'test1',
id:'1',
type:'t',
}];
return $scope.addnew= function() {
.........
something
};
在我的指令,我創造了動態元素;
app.directive('mytree', [
'$timeout', function($timeout) {
return {
restrict: 'E',
controller: function($scope) {
$scope.launch = function (mn) {........something.....}},
template: "<a ng-click='addnew()'>Click</a>",
replace: true,
scope: {
treeData: '=',
onSelect: '&',
initialSelection: '@',
treeControl: '='
}
...........
}}]);
我想從動態創建的元素中調用'addnew'函數。
[Angular:在使用&的指令鏈接函數中調用控制器函數]可能的副本(http://stackoverflow.com/questions/16839259/angular-calling-controller-function-inside-a-directive-link-功能使用) – CodingIntrigue