angularjs - Angular.js ui-sref is not creating hyperlink -
i know question might stupid,but after searching through on stackoverflow , other blogs,and video tutorials,i have no other choice left ask on stackoverflow. have been learning angular.js through online tutorials.
i have 2 files. index.html , app.js
here snaps of code.
states configuration part inside app.js
angular.module('flappernews', ['ui.router']).config(['$stateprovider','$urlrouterprovider',function($stateprovider, $urlrouterprovider) {$stateprovider .state('home', { url: '/home', templateurl: '/home.html', controller: 'mainctrl' }) .state('posts', { url: '/posts/{id}', templateurl: '/posts.html', controller: 'postsctrl' }) $urlrouterprovider.otherwise('home')}]);
inline templates inside index.html (1-home.html , 2-posts.html)
<ui-view></ui-view> <script type="text/ng-template" id="/home.html"> <!--home.html part--> </script> <script type="text/ng-template" id="/posts.html"> <!--posts.html part--> </script>
inside home.html have hyperlink on comments.
<div ng-repeat="post in posts | orderby:'-upvotes'"> <span class="glyphicon glyphicon-thumbs-up" ng-click="incrementupvotes(post)"></span> {{post.upvotes}} <span style="font-size:20px; margin-left:10px;"> <a ng-show="post.link" href="{{post.link}}"> {{post.title}} </a> <span ng-hide="post.link"> {{post.title}} </span> <span> <a ui-sref="/posts/{{$index}}">comments</a> </span> </span> </div>
now when run webapp on localhost showing rendered html of comment hyperlink,but not providing me navigation(hyperlink not working).
<span> <a ui-sref="/posts/0">comments</a> </span>
now,i have 2 questions:
- what went wrong ui-sref part.when use href instead of ui-sref working fine.why happening?
- i have been using inline templates home.html , posts.html,but if make them separate files entire app gets broken.why?
any appreciative.
1)the way have used ui-sref
causing break.try in application,
<a ui-sref="posts({ id: $index })">comments</a>
2)assuming new template files same level index.html , app.js need not mention templateurl: '/posts.html'
,just use templateurl: 'posts.html'
.
Comments
Post a Comment