简体   繁体   中英

ionic collection-repeat working navigation not working on click

I am new to ionic and angular.js. I download this ionic collection repeat and navigation example from http://codepen.io/ionic/pen/mypxez . The initial example was working perfect with single index.html and index.js files. I tried to separate the code in controller, service, app.js and in the HTML files. I can see the collections but I am not able to see the details and navigate it. Here is the HTML file to show all collection which works:

<ion-view title="Home">
<ion-header-bar class="bar-subheader item-input-inset">
<label class="item-input-wrapper">
<i class="icon ion-ios7-search placeholder-icon"></i>
<input type="search" placeholder="Search" ng-model="filter">
</label>
</ion-header-bar>
<ion-nav-buttons side="right">
<a class="button" ng-click="scrollBottom()">
Scroll To Bottom
</a>
</ion-nav-buttons>
<ion-content>
<div class="list">
<a class="item my-item item-thumbnail-left"
collection-repeat="pet in pets | filter:filter"
collection-item-height="90" collection-item-width="'100%'"
ui-sref="tab.detail({petsId: pet.id })">
<img ng-src="http://placekitten.com/60/{{55 + ($index % 10)}}">
<h2>{{pet.firstName}}</h2>
<p>{{pet.id}}</p>
</a>
</div>
</ion-content>
</ion-view>

Here is the code of app.js:

.state('tab.dash', {
url: '/dash',
views: {
'tab-dash': {
templateUrl: 'templates/tab-dash.html',
controller: 'DashCtrl'
}
}
})
.state('tab.detail', {
url: "/detail/:petsId",
views: {
'main': {
controller:'DetailCtrl',
templateUrl: "templates/question-detail.html"
}
}
})

Here is the code of the controller which never get called:

.controller('DetailCtrl', function($scope, $stateParams, PetService) {
$scope.pet = PetService.get($stateParams.petsId);
})

...and the question-detail.html code:

<ion-view title="{{pet.id}}">
<ion-content class="padding">
{{pet.id}}
{{pet.firstName}}
</ion-content>
</ion-view> 

I can view the collection and can search but I am not able to see the details by clicking them. I can see the url ( http://localhost:8100/#/tab/detail/2 ) if i click on item 2 but i am not able to see the question- detail.html page.

Considering you are very new to this framework, or angularJS itself. I am just going to answer the question without saying anything else, but for future, please go through docs first.

<ion-view title="{{pet.id}}">
<ion-content class="padding">
<a href="detail/{{pet.id}}">{{pet.id}}</a>
{{pet.firstName}}
</ion-content>
</ion-view> 

Thanks karan for your prompt answer.. I changed two things and the code is working now:

the html file where i declared the anchor tag. I changed the ui-sref to href:

<div class="list">
                    <a class="item my-item item-thumbnail-left"
                       collection-repeat="pet in pets | filter:filter"
                       collection-item-height="90"
                       collection-item-width="'100%'" href="#/tab/detail/{{pet.id}}">
                      <img ng-src="http://placekitten.com/60/{{55 + ($index % 10)}}">
                        <h2>{{pet.firstName}}</h2>
                        <p>{{pet.id}}</p>

                        </a>
                      </div>

my app.js file

 .state('tab.detail', {
    url: '/detail/:petsId',
    views: {
      'tab-chats': {
        templateUrl: 'templates/question-detail.html',
        controller:'DetailCtrl'

      }
    }
  })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM