【发布时间】:2014-01-28 09:13:50
【问题描述】:
我尝试将一个参数从指令传递到控制器中定义的方法。
我使用隔离范围。
这里是相关代码和Demo in Fiddle:
HTML
<div ng-controller="MapCtrl">
<map id="map_canvas" call='callMe()'></map>
</div>
JS
var module = angular.module('googleMap', []);
module.directive('map', function() {
return {
restrict: 'E',
replace: true,
scope:{
callMe : '&call'
},
template: '<div></div>',
link: function(scope, element, attrs) {
console.log(element);
/* ... */
scope.callMe('hey');
/* ... */
}
};
});
function MapCtrl($scope) {
$scope.callMe = function(val){
alert(val);
};
}
为什么我得到val=undefined?应该是hey
谢谢,
【问题讨论】:
标签: angularjs angularjs-directive