我有一个配置文件列表,其中每个配置文件可以是摘要或详细视图.任何时候只有一个配置文件可以有详细的视图.
profiles.html
<div ng-repeat="profile in profiles">
<div ui-view="profile-summary"></div>
<div ui-view="profile-details"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
型材summary.html
<div ng-if="$state.params.profileId !== profile.id">
{{ profile.name }}
<button ng-click="showProfileDetails(profile.id)">More</button>
</div>
Run Code Online (Sandbox Code Playgroud)
简介 - 汇总controller.js
$scope.showProfileDetails = function(profileId) {
$state.go('profiles.profile', { profileId: profileId });
};
Run Code Online (Sandbox Code Playgroud)
profile-details .html
<div ng-if="$state.params.profileId === profile.id">
Detailed profile of {{ profile.name }}
<button ng-click="hideProfileDetails()">Less</button>
</div>
Run Code Online (Sandbox Code Playgroud)
型材细节,controller.js
$scope.hideProfileDetails = function() {
$state.go('profiles.profile', { profileId: null });
};
Run Code Online (Sandbox Code Playgroud)
ui-router配置
$stateProvider
.state('profiles', {
url: '/profiles?keywords',
views: {
'profiles': {
templateUrl: 'profiles.html',
controller: 'ProfilesCtrl'
},
'profile-summary@profiles': { …Run Code Online (Sandbox Code Playgroud)