我使用AngularJS 1.5.7版進行編碼。指令不接收對象作爲參數
由於某些原因,該指令沒有收到變量cdata
這是一個object
。
爲什麼指令不接收變量?
這裏下面我貼我的所有代碼:
home.js
'use strict';
var home = angular.module('app.home', [
'global.factory',
'home.factory',
'ui.scroll',
'ui.scroll.jqlite',
'd.card'
]);
home.controller('HomeController', [
'homeFactory',
'$timeout',
function (homeFactory, $timeout) {
var data = this;
data.posterSize = (screen.width - 42)/3;
homeFactory.getJSON().then(function (response) {
data.feed = response.home;
});
data.datasource = {
get: function(index, count, success) {
$timeout(function() {
var start = Math.max(0, index);
var end = Math.min(index + count, data.feed.length);
var results = [];
for (var i = start; i < end; i++) {
results.push(data.feed[i]);
}
success(results);
}, 100);
}
};
}
]);
_home.html
<article ng-controller="HomeController as myHome" class="base-gen" ui-scroll-viewport style="height:100%">
<card class="card" ui-scroll="element in myHome.datasource" cdata="{{element}}" psize="{{myHome.posterSize}}"></card>
</article>
card.js
'use strict';
var dCard = angular.module('d.card', ['global.factory']);
dCard.directive('card', [ 'globalImages', function (globalImages) {
return {
restrict: 'E',
scope: {
cdata: '@',
psize: '@'
},
controller: function() {
console.log(this.cdata);
},
controllerAs: 'myCard',
bindToController: true,
templateUrl: 'app/Modules/card.html'
};
}]);
我也想指出的是,我從遷移到angular 1.4.8
和1.5.7
從ui-router 0.2.15
到0.3.1
可能與[這個答案](http://stackoverflow.com/a/ 31013435/2435473) –
聽起來像是問題與ui-scroll模塊有關。拿到涼亭後,沒有更多的問題。謝謝大家! – DevStarlight