以下是app.js
.state('search', {
url: '/search',
templateUrl: 'templates/search-pages/home.html',
controller: 'SearchController'
})
.state('search/search-form', {
url: '/search/search-form',
templateUrl: 'templates/search-pages/search-form.html',
controller: 'SearchController'
})
.state('search/search-form-settings', {
url: '/search/search-form-settings',
templateUrl: 'templates/search-pages/search-form-settings.html',
controller: 'SearchController'
})
$urlRouterProvider.otherwise('/search');
home.html
<ion-view>
<ion-nav-buttons side="right">
<a class="button button-icon icon ion-android-search" href="#search/search-form"></a>
</ion-nav-buttons>
<ion-content class="padding">
<div ng-repeat="data in searchResult">
{{data.title}}
</div>
</ion-content>
</ion-view>
点击页面下方的点击按钮即可打开。
searchForm.html
:
<ion-nav-buttons side="right">
<button class="button button-icon icon ion-android-done" ng-disabled="npubmUsrLocForm.form.$invalid" ng-click="searchByTag()"></button>
</ion-nav-buttons>
这里是searchControllet.js
:
$scope.searchResult = [{title:"this is 1"},{title:"this is 2"}];
alert("init");
$scope.searchByTag = function()
{
$scope.searchResult.push({title:"this is 3"});
$scope.searchResult.push({title:"this is 4"});
$state.go('search');
alert($scope.searchResult.length);
在此警报中显示lengh 4但在HTML页面中仅显示{title:"this is 1"},{title:"this is 2"}
答案 0 :(得分:1)
需要修复的两件事是你的状态和你的网址:
.state('search', {
url: '/search',
templateUrl: 'templates/search-pages/home.html',
controller: 'SearchController'
})
.state('search.search-form', {
url: '/search-form',
templateUrl: 'templates/search-pages/search-form.html',
controller: 'SearchController'
})
.state('search.search-form-settings', {
url: '/search-form-settings',
templateUrl: 'templates/search-pages/search-form-settings.html',
controller: 'SearchController'
})
$urlRouterProvider.otherwise('/search');
各州的格式应为“parent.child”。不是父母/孩子&#39;。
网址与父网址相对。
然后你的HTML应该是这样的:
<ion-view>
<ion-nav-buttons side="right">
<a class="button button-icon icon ion-android-search" ui-sref="search.search-form"></a>
</ion-nav-buttons>
<ion-content class="padding">
<ui-view/>
<div ng-repeat="data in searchResult">
{{data.title}}
</div>
</ion-content>
</ion-view>