我將控制器$ 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')
}
最佳, 奧斯汀
不要將其設置成你的紐帶作用,把它在你的'範圍{}'選項已經創造我關於你的指令的範圍 –