私が欲しいものを得るためにはSO以下の質問をしました。AngularJSはパラメータ付き部分テンプレートを作成します
create a single html view for multiple partial views in angularjs
AngularJs Include Partial Template
angularjs partial template with specific scopeは - 私が欲しいものに近い見えます。
しかし、私のケースはすべてのものとは異なると思います。したがって、質問。
私はこれを何度も繰り返す必要があるHTML
構造を持っています。
<tr>
<td>
Enitity1
</td>
<td>
<input type="radio" name="entity1" value="option1" />
</td>
<td>
<input type="radio" name="entity1" value="option2" />
</td>
<td>
<input type="radio" name="entity1" value="option3" />
</td>
<td>
<input type="radio" name="entity1" value="option4" />
</td>
<td>
<input type="radio" name="entity1" value="option5" />
</td>
</tr>
エンティティの名前をパラメータとして渡し、パラメータに基づいてこのHTMLテンプレートをレンダリングします。
私は以下のようなテンプレートを作成しました。
<tr>
<td>
{{entity}}
</td>
<td>
<input type="radio" name="{{entity}}" value="option1" />
</td>
<td>
<input type="radio" name="{{entity}}" value="option2" />
</td>
<td>
<input type="radio" name="{{entity}}" value="option3" />
</td>
<td>
<input type="radio" name="{{entity}}" value="option4" />
</td>
<td>
<input type="radio" name="{{entity}}" value="option5" />
</td>
</tr>
私のコントローラ
app.controller("entitiesController", ["$scope",
function entitiesController($scope) {
$scope.init = function init(entity) {
$scope.entity= entity;
};
}
]);
そして私は<tbody>
要素内に以下のように複数のエンティティのために同じことをレンダリングしようとしています。
<ng-include src="Common/entities.html" ng-controller="entitiesController" ng-init="init('Entity1')"></ng-include>
<ng-include src="Common/entities.html" ng-controller="entitiesController" ng-init="init('Entity2')"></ng-include>
<!-- Some more entities here...-->
しかし、動作しません。コンソールにもエラーは表示されません。
どうすればよいですか?これを処理する適切な方法は何ですか?それをテンプレートで処理することは可能ですか?それとも、すべてのエンティティに対してHTMLを手動で入力する必要がありますか?
のように使うことができますか? – tanmay
@tanmayまあ、私はAngularJSに比較的新しいです。このような状況で指令がどのように機能するかを簡単にご説明いただけますか? –
私は最近、基本的なディレクティブをいくつか作成しましたが、HTMLテンプレートを生成または挿入することはできません。 –