I have a 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 and ngRoute to display two pages.
The first is a list of stories/posts pulled from a json file. This displays part of the content in the json file - I have limited the amount of text.
I'd like to able to click on these and to open a new view that displays the full content of that story/post clicked.
I have added a story.html that opens when the story/post is clicked on the first view.
My problem is comnecting the scope to the story.html view. I need to know the correct part of the josn to load to match the story/post that is 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 for the home page
.when('/', {
templateUrl: 'home.html',
controller: 'myCtrl'
})
.when('/story', {
templateUrl: 'story.html',
controller: 'storyCtrl'
})
});