[英]ng-change does not trigger
ng-change不會觸發我的功能,這是視圖;
<div ng-controller="widgets.lunchMenu as vm">
<label class="btn btn-transparent grey-salsa btn-circle btn-sm active">
<input type="radio" name="options" class="toggle" id="option1" ng-model="vm.takeCount" ng-value="0" ng-change="vm.getLunchMenus()">@L("Today")
</label>
<label class="btn btn-transparent grey-salsa btn-circle btn-sm">
<input type="radio" name="options" class="toggle" id="option2" ng-model="vm.takeCount" ng-value="7" ng-change="vm.getLunchMenus()">@L("Week")
</label>
<label class="btn btn-transparent grey-salsa btn-circle btn-sm">
<input type="radio" name="options" class="toggle" id="option3" ng-model="vm.takeCount" ng-value="30" ng-change="vm.getLunchMenus()">@L("Month")
</label>
</div>
這是控制器:
(function () {
appModule.controller('widgets.lunchMenu', [
'$scope', 'abp.services.app.lunch',
function ($scope, appService) {
var vm = this;
var today = new Date();
var month = today.getMonth();
vm.getLunchMenus = function () {
appService.getLunchMenus({ month: month + 1, takeCount: vm.takeCount }).success(function (data) {
vm.menus = data.items;
});;
};
vm.getLunchMenus();
}
]);
})();
有什么建議嗎? 感謝您的幫助。
為了使ng-change
指令能夠看到vm.getLunchMenus
函數,它必須位於$scope
。 因此,您需要執行以下操作:
$scope.vm = this;
$scope.vm = function() { ... }
然后在標記中,您可以做您正在做的事情
ng-change="vm.getLunchMenus()"
或者您可以做一些簡單的事情
$scope.getLunchMenus = function() { ... }
然后在標記中:
ng-change="getLunchmenus()"
完全不需要vm
變量,因為this
實際上對標記中的指令( ng-change
等)沒有任何意義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.