Angular 2/Dartコンポーネントに使用するtemplateUrlを動的に切り替える必要があります。ダーツで角度2で動的コンポーネントを作成する方法は?
私は、テンプレートURLを配置するための新しいコンポーネントを動的に作成する方法が分かっています。 TypeScriptを持つAngular 2 ComponentResolver for example this oneを使用してこれを実現する方法の例がいくつかありますが、私はそれらをDartに変換することに失敗しています。
は基本的に私は、関数から新しいコンポーネントを渡してやって失敗するもの:
createComponentFactory(ComponentResolver resolver,
ComponentMetadata metadata) {
final cmpClass = class DynamicComponent {};
final decoratedCmp = Component(metadata)(cmpClass);
return resolver.resolveComponent(decoratedCmp);
}
これとダートと他の同様のアプローチでの問題は、私は変数にclass DynamicComponent {};
を設定するか、からそれを返すことができないということですこのようなエラーを構築取得せず機能:私は、動的コンポーネントを作成するために見てきた例のいずれかを以下のとき
[DirectiveProcessor]:
Failed with 5 errors
Error 1: line 37, column 22 of lib/projects/project_component.dart and parts: Expected an identifier
final cmpClass = class DynamicComponent {};
^^^^^
Error 2: line 37, column 22 of lib/projects/project_component.dart and parts: Expected to find ';'
final cmpClass = class DynamicComponent {};
^^^^^
Error 3: line 37, column 22 of lib/projects/project_component.dart and parts: Expected a statement
final cmpClass = class DynamicComponent {};
^^^^^
Error 4: line 37, column 22 of lib/projects/project_component.dart and parts: Unexpected token 'class'
final cmpClass = class DynamicComponent {};
^^^^^
Error 5: line 37, column 28 of lib/projects/project_component.dart and parts: Expected to find ';'
final cmpClass = class DynamicComponent {};
^^^^^^^^^^^^^^^^
このような新しいコンポーネントを作成するには、私のために、共通のつまずきの石です。あなたはダーツでこれをどのように達成することができますか?
多くの感謝!これは私がクラス宣言で持っていた問題を解決します。私はまだ全体のソリューションに取り組んでおり、いったん正しく動作するものがあれば、ここで最終バージョンを投稿します。 – DarthKipsu