我将控制器$ scope函数传递给通过html属性的指令,但由于某种原因,指令认为函数是字符串。任何提示?
HTML
<modal show='createCustomer' create-new-customer='createNewCustomer()'></modal>
指令
function modalDialog() {
return {
restrict: 'AE',
scope:{
createNewCustomer: '&'
},
replace: true,
transclude: true,
link: function(scope, element, attrs) {
scope.createNewCustomer = attrs.createNewCustomer;
console.log(typeof scope.createNewCustomer)
},
templateUrl: "./views/directive_templates/modal.html"
};
}
$范围功能
$scope.createNewCustomer = function(){
alert('yo')
}
最佳, 奥斯汀
不要将其设置成你的纽带作用,把它在你的'范围{}'选项已经创造我关于你的指令的范围 –