1
我正在使用Angular UI路由器,當我點擊導航欄中的任何選項時,它會將相應的狀態加載到子視圖中。但問題是每當我點擊導航欄中的任何列表項時,它也會加載父項,並將導航欄重置爲默認值。 如何解決此問題,每當我單擊任何此導航欄項目時,它都會將相應的狀態加載到子視圖中,但不會重置父級項目。在AngularJS中加載沒有刷新父狀態的子狀態
檢查此gif以瞭解問題。
這是我在app.js config
塊
// Routes defined in config
app.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/dashboard');
$stateProvider
// Home route
.state('dashboard', {
url: '/dashboard',
views: {
'': {
templateUrl: 'views/dashboard.html' ,
controller : 'mainCtrl'
},
'[email protected]': {
templateUrl: 'views/home.html',
controller: 'homeController'
}
}
})
//login route
.state('login',{
url: '/login',
templateUrl: 'views/login.html',
controller: 'authController'
})
.state('logout',{
controller:'logout'
})
//Add role
.state('addRole',{
url: '/addRole',
views: {
'': {
templateUrl: 'views/dashboard.html' ,
controller : 'mainCtrl'
},
'[email protected]': {
templateUrl: 'views/addRole.html',
controller: 'addRole'
}
}
})
//Add role
.state('getUserInfoData',{
url: '/getUserInfoData',
views: {
'': {
templateUrl: 'views/dashboard.html' ,
controller : 'mainCtrl'
},
'[email protected]': {
templateUrl: 'views/getUserInfoData.html',
controller: 'getUserInfoData'
}
}
})
//manage role
.state('manageRole',{
url: '/manageRole',
views: {
'': {
templateUrl: 'views/dashboard.html' ,
controller : 'mainCtrl'
},
'[email protected]': {
templateUrl: 'views/manageRole.html',
controller: 'manageRole'
}
}
})
.state('manageUsers',{
url: '/manageUsers',
views: {
'': {
templateUrl: 'views/dashboard.html',
controller : 'mainCtrl'
},
'[email protected]': {
templateUrl: 'views/manageUsers.html',
controller: 'manageUsers'
}
}
})
.state('sendSms',{
url: '/sendSms',
views: {
'': {
templateUrl: 'views/dashboard.html',
controller : 'mainCtrl'
},
'[email protected]': {
templateUrl: 'views/sendSms.html',
controller : 'smsController'
}
}
})
//Manage Import/Export CSV
.state('manageCsv',{
url: '/manageCsv',
views: {
'': {
templateUrl: 'views/dashboard.html' ,
controller : 'mainCtrl'
},
'[email protected]': {
templateUrl: 'views/manageCsv.html',
controller: 'manageCsv'
}
}
})
// Check user Route
.state('checkUser', {
url: '/',
controller: 'checkController'
})
// List All Claim
.state('createForm', {
url: '/createForm',
views: {
'': {
templateUrl: 'views/dashboard.html' ,
controller : 'mainCtrl'
},
'[email protected]': {
templateUrl:'views/createForm.html',
controller: 'createForm'
}
}
})
//list claim profile
.state('claimProfile', {
url: '/claimProfile/:id',
views: {
'': {
templateUrl: 'views/dashboard.html' ,
controller : 'mainCtrl'
},
'[email protected]': {
templateUrl:'views/claimProfile.html',
controller: 'claimProfile'
}
}
})
//list all forms
.state('manageForms', {
url: '/manageForms',
views: {
'': {
templateUrl: 'views/dashboard.html' ,
controller : 'mainCtrl'
},
'[email protected]': {
templateUrl:'views/manageForms.html',
controller: 'manageForms'
}
}
});
});
這是我的HTML
<div class="left-sidebar-section">
<div class="section-title">Claims</div>
<ul class="list-unstyled" id="form-components">
<li ui-sref="getUserInfoData">
<button class="btn btn-flat" data-parent="#form-components" ng-class="{activeMenu : isActive('/getUserInfoData')}">
<span class="btn-title">
<a>Users Data</a>
</span>
<i class="material-icons pull-left icon">folder</i>
</button>
</li>
</ul>
</div>
Thankyou非常..它解決了我的問題,但是當我把'abstract:true,'它顯示一個錯誤。無論如何,當我不把它,代碼工作正常。 ':)'我不知道爲什麼,但它的工作..謝謝你@yBrodsky – gauravmehla