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.config(function(RestangularProvider) { | |
| // First let's set listTypeIsArray to false, as we have the array wrapped in some other object. | |
| RestangularProvider.setListTypeIsArray(false); | |
| // Now let's configure the response extractor for each request | |
| RestangularProvider.setResponseExtractor(function(response, operation, what, url) { | |
| var newResponse; | |
| // This is a get for a list | |
| if (operation === "getList") { | |
| // First the newResponse will be response.objects which is actually an array |
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
| angular.module("test").service("Greeting", function() { | |
| this.greet = null; | |
| this.greetTo = function(name) { | |
| this.greet = "Hello " + name; | |
| } | |
| }); | |
| angular.module("test").controller("TestCtrl", function(Greeting) { | |
| $scope.greeting = Greeting; |
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
| // This will return a promise of an Array | |
| var promisedArray = $q.when([1,2,3]); | |
| //Normal way of getting length in angular | |
| promisedArray.then(function(arr) { | |
| var length = arr.length; | |
| // Do something with length in callback | |
| }) | |
| //Using promises transformation |
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
| function enhancePromise(promise, isCollection) { | |
| promise.call = angular.bind(promise, promiseCall); | |
| promise.get = angular.bind(promise, promiseGet); | |
| return promise; | |
| } | |
| function promiseCall(method) { | |
| var deferred = $q.defer(); | |
| var callArgs = arguments; | |
| this.then(function(val) { |
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 buildings = Restangular.all("buildings").getList(); | |
| // New promise after adding the new building | |
| // Now you can show in scope this newBuildings promise and it'll show all the buildings | |
| // received from server plus the new one added | |
| var newBuildings = buildings.push({name: "gonto"}); | |
| var newBuildingsSame = buildings.call("push", {name: "gonto"}); | |
| // This is a promise of a number value. You can show it in the UI |
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
| <html> | |
| <head> | |
| <!-- Include here Styles and AngularJS scripts--> | |
| </head> | |
| <body> | |
| <div class="container" ng-app="example" ng-controller="MainCtrl" ng-cloak> | |
| <header> | |
| <div>This is the common headers for all of the tabs of this little app</div> | |
| </header> | |
| <!-- This is the div that will change when the URL changes via the $routeProvider--> |
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
| 'use strict'; | |
| /** | |
| * Application start point. | |
| * | |
| * Note, we use minifyer, so all dependencies should be explicitly defined with ['<dependency>', | |
| * function(<dependency>) {}]; | |
| */ | |
| var module = angular.module('example', | |
| [ 'restangular', 'ngResource']).config( |
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
| <div> | |
| <h1>First Tab</h1> | |
| <input type="text" ng-model="query.searchText" /> | |
| <pie data="data.valuesData | forPie" type="valuesPie" /> | |
| </div> |
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
| module.directive('pie', function () { | |
| return { | |
| replace: true, | |
| restrict: 'EA', | |
| scope: {type: '@', data:'='}, | |
| templateUrl: "/js/test/angular/partials/pie.html", | |
| controller: ['$scope', '$routeParams', '$element', '$filter', function($scope, $routeParams, $element, $filter) { | |
| $scope.$watch('data', function() { | |
| if (_.isUndefined($scope.data) || _.isNull($scope.data) || $filter('isZeroData')($scope.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
| var userResource = $resource('/users/:userId', {}, { | |
| getList: {method: 'GET', params: {}, isArray: true}, | |
| get: {method: 'GET', params: {}, isArray: false}, | |
| }); | |
| var users = userResource.getList(); | |
| var user = userResource.get({userId: 123}) | |
| // Later in the code | |
| var carResource = $resource('/users/:userId/cars/:carId', {}, { |