将对象数组绑定到Angular组件

时间:2016-11-24 14:19:54

标签: angularjs angular-components

我有一个内置ui-gid的组件,我想将数据传递给网格。数据来自$ http调用Web Api。 从服务器到达时不显示数据 - 组件内的网格​​为空。 问题是在数据从服务器到达之前,绑定发生在“早期”。将对象数组绑定到组件的正确方法是什么?

这是我的组成部分:

.component('gridComponent', {
        bindings: {
            gridData: '<',
            gridSelected: '<?', //selected objects to set
            gridColumns: '<?',
            gridOnchange: '&',
        },
        templateUrl: 'Angular/common/components/grid-component/grid.component.html',
        controller: GridComponentController
    });

ctrl.$onInit = function () {
        if (angular.isDefined(ctrl.gridColumns))
            ctrl.grid.columnDefs = ctrl.gridColumns;
        ctrl.grid.data = ctrl.gridData;

    };

HTML:

<grid-component  grid-data="vm.shops" grid-columns="vm.shopsColumns" grid-selected="vm.selectedShops"
                          grid-onchange="vm.changeSelected(selected, isChecked)"></grid-component>

我也尝试过双向绑定,但没有运气。 唯一可行的方法是当我将ng-if = vm.shops.length&gt; 0放到包含此组件的某个div时,但我认为这不是一个好的解决方案。

0 个答案:

没有答案
相关问题