Created
December 15, 2014 16:42
-
-
Save got5/d6967f57d23c5d2a17a2 to your computer and use it in GitHub Desktop.
Slide71 TP3
This file contains 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
(function(){ | |
"use strict"; | |
angular.module('app') | |
.factory('NewsService',['$resource', function ($resource) { | |
return $resource('/api/news/:op/:id',{id:'@id'},{ | |
like: {method:'GET',params: {op:'like'}}, | |
random: {method:'GET',params:{op:'random'}} | |
}); | |
}]); | |
})(); |
This file contains 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
<script src="vendor/angular-resource/angular-resource.js"></script> |
This file contains 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('app', [ 'ngCookies', 'ngRoute','ngResource', 'ui.bootstrap', 'pascalprecht.translate']); |
This file contains 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
(function () { | |
"use strict"; | |
/** Home view controller */ | |
angular.module('app') | |
.controller('HomeController', ['$scope','NewsService', function ($scope,NewsService) { | |
$scope.message = "Welcome in our shop!!!"; | |
/** Gets all the news. */ | |
$scope.lstNews = NewsService.query(); | |
/** Gets the news with id = 1. */ | |
$scope.currentNews = NewsService.get({ id: 1 }); | |
$scope.newsOfTheDay = NewsService.random(); | |
/** Creates a new news. */ | |
$scope.addedNews = new NewsService(); | |
/** Increments the number of likes of a news, and saves the changes. */ | |
$scope.addLike = function(news) { | |
news.$like(); | |
}; | |
/** Deletes a news. */ | |
$scope.deleteNews = function(news) { | |
news.$delete(function(){ | |
$scope.lstNews.splice($scope.lstNews.indexOf(news),1); | |
}); | |
}; | |
/** Adds a news. */ | |
$scope.addNews = function() { | |
$scope.addedNews.$save(function(){ | |
$scope.lstNews.push($scope.addedNews); | |
$scope.addedNews = new NewsService(); | |
}); | |
}; | |
}]); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment