2016-12-01 3 views
1

Я не очень удобен с привязками в угловом (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", и я не понимаю, почему.

+0

В файле mapping.html вы переходите к компоненту mc.canvasdata и mc.renditions. У вас есть они определены в map.component? –

+0

Да, ниже var Drupal = new $ newDrupal(); они определяются как mc.canvasdata = new Array(); mc.renditions = new Array(); – Antoine

ответ

0

В самом деле, в моем index.route.js я имел

.state('main.publication.paragraph', { 
     url: '/paragraphs/:idParagraph/page/:idPageParagraphs', 
     templateUrl: 'app/pages/rendition-map.html' 
     }) 

но в rendition-map.html, я звоню <rendition> вместо <mapping>, который зовет себя <rendition>, поэтому переменные были неопределенными, и мне пришлось выполнить обещание сделать это.

rendition-map.html 
<mapping></mapping> 

mapping.html 
<rendition renditions="mc.renditionsPromise"></rendition> 
0

Похоже, rendition не является ребенком mapping, поэтому mc.canvasdata не определено.

Установите mapping шаблон:

<mapping> 
    <rendition canvas="mc.canvasdata"...></rendition> 
</mapping> 
+0

последний раз, когда кто-то говорил о «ребенке», мне пришлось использовать , может быть это причина? Я проверю эту сторону. – Antoine

+0

структурирование компонентов в иерархии не имеет ничего общего с ui-view ... – gyc

Смежные вопросы