0
我已经用UI-Router multiple named views not working的顶级解决方案与我的角度应用程序差不多,但我的UI视图似乎没有更新,而只是完全消失。必须有一些非常小的细节,我错过了很长一段时间...Angularjs ui-view没有更新
我有一个index.html页面,[div ui-view =“”]在主场换下。这个ui-view(frontpage.html)有另一个[div ui-view =“search-result”],我希望从状态变化中更新(将文本更改为“成功的模板替换”),但是当状态改变时,当点击搜索按钮时,index.html中的整个[div ui-view =“”]消失。
所有相关的脚本标签都包含在我的index.html中。
的index.html:
<body ng-app="...">
<div class="container">
<div ui-view=""></div>
</div>
app.js:
angular.module('...', [ 'ui.router','ui.bootstrap']).
config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('main', {
url: "/",
templateUrl: "/app/states/frontpage/frontpage.html"
})
.state('search', {
url : "/search/:query",
views: {
'[email protected]': {
template: 'successful template replacement'
}
}
}).run(function(){});
frontpage.html:
<div class="row" ng-controller="MainController">
some stuff here
<div class="col-xs-9">
<input type="text" class="inline" ng-model="searchText" placeholder="Search..."></input>
<button class="btn btn-default inline" type="button" ng-click="search()">Search</button>
<div ui-view="search-result"></div>
</div>
</div>
mainCtrl.js
angular.module('...')
.controller('MainController', ['$scope','$state', function($scope,$state) {
$scope.searchText;
$scope.search = function(){
console.log('going to state search with searchText: ' + $scope.searchText);
$state.go('search',{query:$scope.searchText});
}
}]);
我加父线到“搜索“状态。现在没有任何反应(至少从页面上消失)。还尝试通过删除初始斜杠来更改搜索网址为“search /:query”,因此URL顶部栏中没有2个斜杠 – user3125693