私はバインドを介して取得する文字列に応じて異なるメニュー構造を表示する左手のメニューコンポーネントを作成したいと思います。例えば角度1.5とTypescriptを使用してコンポーネントコントローラでバインディング値を取得する方法はありますか?
:
<left-hand-menu-component module='abc'></left-hand-menu-component>
そして、それが唯一のABCモジュールのメニュー構造を示しています。これを達成するためには、コンポーネントコントローラがデータとの連携が可能でなければならず、必要なサービスコールを行う必要があります。
私はしばらくの間、これを達成するためにグーグルで行っており、私はthisとthis投稿とthis投稿を見つけました。 Angularのドキュメントで利用できる例はあまりにも単純です。
私は上記の例のコードをまとめてあり、コントローラーが値渡しのバインディングを処理できるときにその部分が欠落しています。
でも可能ですか?それとも、コンポーネントよりもむしろディレクティブですか?
表示されている場所、ブログエントリ、またはソースなどの例をご存知ですか?
コントローラコンストラクタの2つのconsole.logは、結果として「undefined」を書き出します。
コンポーネント:
module qa.gonogo {
"use strict";
export class LeftHandMenuComponent implements ng.IComponentOptions {
public transclude: boolean = false;
public controller: Function = LeftHandMenuComponentController;
public controllerAs: string = "vm";
public templateUrl: string = "app/content/lefthandmenu/leftHandMenuComponentTemplate.html";
public bindings: any;
constructor() {
this.bindings = {
module: '<'
}
}
}
angular
.module("goNoGo")
.component("gonogoLefthandmenuComponent", new LeftHandMenuComponent());
}
コントローラー:
export class LeftHandMenuComponentController implements ILeftHandMenuComponentController {
menuStructure: IMenuStructure[];
closeOthers: boolean = true;
static $inject = [];
constructor(public module: string) {
console.log('binding', module);
console.log('binding2', this.module);
}
public $onInit =(): void => {
this.populateMenuStructure();
}
ルート。
$stateProvider
.state("bfts",
<ng.ui.IState>{
url: "/bfts",
views: <any>{
"leftHandMenu": <ng.ui.IState>{
template: "<gonogo-lefthandmenu-component module='bfts'></gonogo-lefthandmenu-component>"
},
"content": <ng.ui.IState>{
template: "bfts content"
}
}
});
で遊ぶことができますの名前で、コントローラクラスのプロパティを定義しようとしていますバインドされたプロパティ – toskv
あなたが直面している問題は明確ではありません。はい、可能です。 httpコールをサービスに移動するだけです。 – dfsq
あなたがリンクした最初の投稿には、設定プロパティでFacebookIntegrationControllerに必要なものの例があります。 – toskv