我正在处理角度1组件,我制作了一个接受数据集作为参数的数据表组件。这个是我如何使用datatable
组件。在ajax请求后将参数传递给角度组件
index.html
...
<datatable dataset="ViewModel.dataset"></datatable>
...
index.controller.js
(function() {
'use strict';
angular
.module('DashboardApplication')
.controller('PagesIndexController', PagesIndexController);
function PagesIndexController() {
var self = this;
self.dataset = {};
Restangular.one('someurl').get().then(function(pages) {
self.dataset = pages;
});
}
})();
datatable.component.js
(function() {
'use strict';
angular
.module('DashboardApplication')
.component('datatable', {
bindings: {
dataset: '<'
},
templateUrl: '/frontend/templates/dashboard/components/data-table.html',
controller: 'DataTableController'
});
})();
datatable.controller.js
(function() {
'use strict';
angular
.module('DashboardApplication')
.controller('DataTableController', DataTableController);
function DataTableController() {
var self = this;
console.log(self.dataset); // which is undefined!
}
})();
问题是我得到undefined
为dataset
在datatable.controller.js
。有没有解决方案?
我使用'component',它不需要'controllerAs'。它默认使用'$ ctrl'作为'controllerAs'。 – sadrzadehsina