Angularjs, ng-view scope -


i have plunker here - http://plnkr.co/edit/pzsvkd9m4l1mkjlyluym?p=preview

i'm using demo json here - https://api.myjson.com/bins/1hdr5

i'm using ng-view , ngroute display 2 pages.

the first list of stories/posts pulled json file. displays part of content in json file - have limited amount of text.

i'd able click on these , open new view displays full content of story/post clicked.

i have added story.html opens when story/post clicked on first view.

my problem comnecting scope story.html view. need know correct part of josn load match story/post clicked.

var app = angular.module('myapp', ['ngroute']);  app.service('myservice', function ($http, $q) {      var deferred = $q.defer();     $http.get('https://api.myjson.com/bins/1hdr5').then(function (data) {         deferred.resolve(data);     })      this.getstory = function () {         return deferred.promise;     } })      .controller('myctrl', function ($scope, myservice) {     var promise = myservice.getstory();     promise.then(function (data) {         $scope.stories = data.data.stories;     })  })  /*      .controller('storyctrl', function ($scope, myservice) {     var promise = myservice.getstory();     promise.then(function (data) {         $scope.stories = data.data.stories;     })  }) */       .config(function ($routeprovider) {     $routeprovider      // route home page     .when('/', {         templateurl: 'home.html',         controller: 'myctrl'     })          .when('/story', {         templateurl: 'story.html',         controller: 'storyctrl'     })  }); 

if have different title of each story, in each story inside ng-repeat, in href can pass title in link. have declare variable title in route file after /story , can catch value of dynamic title $routeparams service.

your href this

data-ng-href="#story/{{story.title}}" 

your route this:

.when('/story/:title' 

in story controller can catch title this:

$scope.selectedtitle = $routeparams.title 

based on catched title can take selected story in array of objects containing stories , show html

see updated plunker: http://plnkr.co/edit/b712oernq8bnb6qumedx?p=preview


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -