ng-change不會觸發我的函數,這裏是視圖;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();
}
]);
})();
什麼建議嗎?感謝您的幫助。
你使用什麼版本的角? –
建議:定義'vm = $ scope'或將綁定改爲'$ scope.getLunchMenus()'。你的HTML只與'$ scope'變量和函數交互。 – ryanyuyu
@ryanyuyu海報似乎使用ControllerAs語法(儘管使用'vm'作爲每個控制器的通用名稱有點問題)。改變'vm'指向'$ scope'沒有任何意義。 – Claies