我是angularJS的新手,如何配置ng-click =“reviewCtrl.submit()”函数?
$scope.reviewCtr.submit= function(){
alert("this is alert");
};
<button id="submitBtn" tabindex="50" type="button" ng-click="reviewCtrl.submit()" >Submit</button>
答案 0 :(得分:1)
reviewCtrl
是对controller实例的引用,称为controller-as语法。要使用它,您需要在HTML中使用此表示法:
ng-controller="YourController as reviewCtrl"
和attache submit
函数到控制器而不是$ scope对象:
.controller('YourController', function () {
this.submit = function () {
alert("this is alert")
}
})