我正在處理角度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