1
我試圖調用我已經進入組件的函數。AngularJS - 將函數調用到組件
這裏是我的組件buttonsController代碼:
(function(){
"use strict";
angular
.module('my')
.component('myButton', {
templateUrl: '../app/src/component/buttons.html',
controller: buttonController,
controllerAs: 'btnCmpnt',
bindings: {
newElement: '&',
editElement: '&',
deleteElement: '&',
newTitle: '@',
editTitle: '@',
deleteTitle: '@'
}
});
function buttonController($scope) {
var vm = this;
vm.newElement = () => {
alert("1")
}
vm.editElement = () => {
alert("2")
}
vm.deleteElement = () => {
alert("3")
}
}
})();
這裏是我的buttons.html
<div class="col-md-12">
<button ng-if="btnCmpnt.newTitle" title="Add configuration" class="btn btn-primary btn-md" ng-click="btnCmpnt.newElement()"> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> {{btnCmpnt.newTitle}}</button>
</div>
,這是我的html,我打電話給我的組件:
<my-button new-title="New" new-element="newElement();"></my-button>
我無法打電話給我的功能。
你能幫我嗎?
Regards !!
不錯。這裏是一個演示示例https://plnkr.co/edit/nLm6CSkUBmEA8MIKBsad?p=preview –
@sachilaranawaka謝謝! – dfsq