私は現在、AngularJSを潜在的なMVCフレームワークとして評価しています。次のシナリオを実装するための「正しい」方法は何か疑問に思っています-
ユーザー詳細ページをデザインしているとしましょう。基本情報タブ(名前、メール...)、ユーザーの興味タブ(スポーツ、音楽などのドロップダウン)などのさまざまなタブに分かれています。
したがって、コードは次のようになります。
<!-- main.html-->
<div ng-controller="UserController">
<div ng-switch on="renderPath">
<div ng-switch-when="basicInfo">
<div ng-include src="basicUrl"></div>
</div>
<div ng-switch-when="interests">
<div ng-include src="interestUrl"></div>
</div>
</div>
</div>
そしてinterests.htmlは次のようになります
<div>
<div class="dropdown">
<a class="dropdown-toggle" id="dLabel" role="button" data-toggle="dropdown" data-target="#" href="/page.html">
I like to play:
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<li ng-repeat="sport in sports">{{sport}}</li>
</ul>
<a class="dropdown-toggle" id="A1" role="button" data-toggle="dropdown" data-target="#" href="/page.html">
I like to listen to:
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<li ng-repeat="genre in genres">{{genre}}</li>
</ul>
</div>
</div>
したがって、問題は、UserControllerの他に、「 basicInfo 」タブと「interests」タブに別々のコントローラーを作成する必要があるかどうかです。InterestsControllerを作成したい理由は、考える必要がないからです。
$scope.sports= ['baseball', 'bastketball'];
$scope.genres= ['pop', 'classical'];
Interest.htmlのみが関心のさまざまな選択を考慮しているため、 UserControllerに存在する必要があります。また、ページには他の多くのタブがあるため、 UserControllerは非常にすばやく取得する可能性があります。
しかし同時に、Angularのドキュメントでは-* " Angularでは、モデルはAngularScopeオブジェクトのプロパティとして到達可能な任意のデータです"*、InterestsControllerなどがある場合、そのモデルはそのタブに必要な情報のみが含まれているため、かなり恣意的です。
では、ベストプラクティスは何ですか?はっきりと説明したいと思います。ありがとうございました。