[英]OnChange of a Component binding in Angular Js
我已經在angular js中創建了一個顯示一些數據的組件,但是在更改客戶綁定后,我想在組件控制器中調用一些未反映的服務,這是下面的代碼
在我的Test1.html中
<tab-customer title="Test Comp" customerCode="vm.customerCode" functioname="fnTest"></tab-customer>
vm.CustomerCode
根據下拉列表進行更改,因此其更改
app.comp.TestComp
已經定義
angular
.module('app.comp.TestComp')
.component('tabCustomer', {
templateUrl: 'Component.html',
controller: tabCompCustomer,
controllerAs: 'vm',
bindings: {
title: '@',
functioname: '@',
customerCode: '<'
}
});
function tabCompCustomer(tableCustomerService, $rootScope,$scope, $filter) {
var vm = this;
$scope.$watch('vm.customerCode', function (newValue, oldValue) {
console.log('got1')
console.log(newValue) // This is also not working
});
$onChanges = function (changes) {
console.log('got')
console.log(changes) // This is also not working
};
};
更改客戶代碼后,我需要再次觸發我的組件,但沒有發生任何觸發事件,有人可以幫忙嗎
如果問題仍不清楚,我將詳細說明
您應該將屬性綁定從customerCode
更改為customer-code
,這樣會將vm.customerCode
傳遞給component。 並從組件控制器中刪除$watch
函數,因為$onChanges
函數將在每次bindings
更改時自動觸發。
customerCode="vm.customerCode"
應該
customer-code="vm.customerCode"
注意:使
$onChanges =
this.$onChanges =
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.