2016-07-24 14 views
0

Angularjs 1.5を使用すると、別のコンポーネントに依存するページの1つのコンポーネント表示で定義されたD3.jsグラフを作成する際に問題が発生しています。私はAngularには新しく、回答はthe official documentation's example of a component treeのどこかに埋もれていると思うが、私はその論理に完全に従うことができなかった。異なるコンポーネント内のコンポーネントへのアクセス

私の目標はグラフをgraphControllerで定義し、それをrequests.template.htmlによってアクセスされるようにすることです。

私はディレクティブは、私が他の誰かから設定を継承(プロテクト構造にそれがある方法を残すことを好むだろう)

不明なプロバイダエラーを与えたのと同じようrequests.componentに注入しようとすると、

requests.module.js 
angular.module("requests", []); 

requests.component.js 
angular.module('requests').component('requests', { 
    templateURL: 'Bindings/Templates/requests.html', 
    controller: function requestsController($scope) { 
     [code] 
    } 
} 

requests.template.html 
//where I'd like to be able to access the controller from the graphs component 

graphs.module.js 
angular.module('graphs', []); 

graphs.component.js 
angular.module('graphs').component('graphs', { 
    templateURL: '/Bindings/Templates/graphs.template.html', 
    controller: function graph() {(code for d3 graph)}; 
} 

graphs.template.js 
{{$ctrl.graph()}} 
//this page is just a placeholder to see the graph until I can view it on requests' page 

このコントローラーコールをどのようにスレッド化すればよいかを教えてください。ありがとう!

+0

まず、コンポーネントのスコープへのアクセスはありません。これは、コンポーネントのスコープが常に分離されているため、指示の概念です。お互いに通信するためにコンポーネントが必要な場合は、必要性を検討する必要があります。 –

答えて

1

リクエスト・コンポーネントにグラフを表示したい場合は、コンポーネント・タグをリクエスト・テンプレート内に挿入するだけです。例えば、バインディング/テンプレート/ requests.html挿入して:あなたはコンポーネントを作成したら

<div class="stuff-to-wrap-graph"> 
    <graphs></graphs> 
</div> 

、あなたが他のコンポーネントの中に含めて、任意の場所に挿入することができますユニークなHTML要素のように考えることもできます。通常、親の密接に結合された子であれば、別のコンポーネントのコントローラに直接アクセスするだけです。親タブコンテナと通話する必要があるタブコンポーネント内の個々のタブ。

関連する問題