我不是很喜歡Angular中的綁定(1.5),每次我嘗試時都會遇到很多麻煩來解決我的問題,所以我想我錯過了某些東西或做錯了事情,我希望你可能會幫助我。AngularJS組件之間的綁定
所以這是mapping.component.js
(function() {
'use strict';
angular
.module('app')
.component('mapping', mapping());
/** @ngInject */
function mapping() {
return {
templateUrl: 'app/containers/mapping/mapping.html',
controller: mappingController,
controllerAs: 'mc'
};
function mappingController($log, $newDrupal, $stateParams, $http) {
var mc = this;
var Drupal = new $newDrupal();
mc.paragraph = Drupal.getParagraphs(...);
.
.
.
$http.get(...).success(function (data) {
}
} ...
rendition.component.js
(function() {
'use strict';
angular
.module('app')
.component('rendition', rendition());
/** @ngInject */
function rendition() {
return {
templateUrl: 'app/components/rendition/rendition.html',
controller: renditionController,
bindings: {
canvasdata: '<',
renditions: '<'
},
controllerAs: 'rd'
};
function renditionController($log, $newDrupal, $stateParams, $http) {
隨着mapping.html
<rendition canvasdata="mc.canvasdata" renditions="mc.renditions"></rendition>
和
rendition.html
<pre> {{ rd.canvas | json }} </pre>
<pre> {{ rd.renditions | json }} </pre>
但rd.canvas和rd.renditions是"undefined"
,我不明白爲什麼。
在mapping.html中,您傳遞給組件mc.canvasdata和mc.renditions。你有沒有在mapping.component中定義它們? –
是的,下面var Drupal = new $ newDrupal();它們被定義爲mc.canvasdata = new Array(); mc.renditions = new Array(); – Antoine