** README **
Last active
December 23, 2015 09:07
-
-
Save sjarifHD/1000077748965034b519 to your computer and use it in GitHub Desktop.
Change $index angularjs with 'something' (eg. 'slug').
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var app = angular.module('myApp', ['ngRoute']); | |
| app.config(function ($routeProvider) { | |
| $routeProvider | |
| .when('/', { | |
| controller: 'HomeController', | |
| templateUrl: 'welcome/listAll' | |
| }) | |
| .when('/read/:slug', { | |
| controller: 'ReadController', | |
| templateUrl: 'welcome/read' | |
| }) | |
| .otherwise({ | |
| redirectTo: '/' | |
| }); | |
| }); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.factory('blogs', ['$http', function ($http) { | |
| return $http.get('api/blog') | |
| .success(function (data) { | |
| return data; | |
| }) | |
| .error(function (data) { | |
| return data; | |
| }); | |
| }]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.controller('ReadController', ['$scope', 'blogs', '$routeParams', function ($scope, blogs, $routeParams) { | |
| // blogs.success(function (data) { | |
| // $scope.detail = data[$routeParams.id]; | |
| // | |
| // }); | |
| blogs.success(function (data) { | |
| data.some(function (blog) { | |
| if (blog.slug === $routeParams.slug) { | |
| $scope.detail = blog; | |
| } | |
| }); | |
| }); | |
| }]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment