gpt4 book ai didi

javascript - Angular Js 中组件绑定(bind)的 OnChange

转载 作者:行者123 更新时间:2023-11-30 15:16:30 25 4
gpt4 key购买 nike

我在 angular js 中创建了一个组件,它显示了一些数据但是在更改我的客户绑定(bind)时,我想在组件 Controller 中调用一些没有反射(reflect)的服务,这是下面的代码

在我的 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
};
};

在更改客户代码时,我需要再次触发我的组件,但我没有收到任何触发事件,任何人都可以帮忙

如果问题还不清楚评论我会详细说明

最佳答案

您应该将属性绑定(bind)从 customerCode 更改为 customer-code,这样会将 vm.customerCode 传递给组件。并从组件 Controller 中删除 $watch 函数,因为 $onChanges 函数将在每次 bindings 更改时自动触发。

customerCode="vm.customerCode"

应该是

customer-code="vm.customerCode"

Note: make $onChanges = to this.$onChanges =

关于javascript - Angular Js 中组件绑定(bind)的 OnChange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44384650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com