在角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传递给组件。并从组件控制器中删除$watch函数,因为$onChanges功能将在每个bindings更改上自动射击。

customerCode="vm.customerCode"

应该是

customer-code="vm.customerCode"

注意:使$onChanges =this.$onChanges =

最新更新