Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see some people asking how to do this using the angular.controller method with minification friendly dependency injection. Since I just got this working I felt obliged to come back and help. Here's my solution (adopted from the original question and Misko's answer):</p> <pre><code>angular.module('phonecat', ['phonecatFilters', 'phonecatServices', 'phonecatDirectives']). config(['$routeProvider', function($routeProvider) { $routeProvider. when('/phones', { templateUrl: 'partials/phone-list.html', controller: PhoneListCtrl, resolve: { phones: ["Phone", "$q", function(Phone, $q) { var deferred = $q.defer(); Phone.query(function(successData) { deferred.resolve(successData); }, function(errorData) { deferred.reject(); // you could optionally pass error data here }); return deferred.promise; ] }, delay: ["$q","$defer", function($q, $defer) { var delay = $q.defer(); $defer(delay.resolve, 1000); return delay.promise; } ] }, }). when('/phones/:phoneId', { templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl, resolve: PhoneDetailCtrl.resolve}). otherwise({redirectTo: '/phones'}); }]); angular.controller("PhoneListCtrl", [ "$scope", "phones", ($scope, phones) { $scope.phones = phones; $scope.orderProp = 'age'; }]); </code></pre> <p>Since this code is derived from the question/most popular answer it is untested, but it should send you in the right direction if you already understand how to make minification friendly angular code. The one part that my own code didn't requires was an injection of "Phone" into the resolve function for 'phones', nor did I use any 'delay' object at all.</p> <p>I also recommend this youtube video <a href="http://www.youtube.com/watch?v=P6KITGRQujQ&amp;list=UUKW92i7iQFuNILqQOUOCrFw&amp;index=4&amp;feature=plcp">http://www.youtube.com/watch?v=P6KITGRQujQ&amp;list=UUKW92i7iQFuNILqQOUOCrFw&amp;index=4&amp;feature=plcp</a> , which helped me quite a bit</p> <p>Should it interest you I've decided to also paste my own code (Written in coffeescript) so you can see how I got it working.</p> <p>FYI, in advance I use a generic controller that helps me do CRUD on several models:</p> <pre><code>appModule.config ['$routeProvider', ($routeProvider) -&gt; genericControllers = ["boards","teachers","classrooms","students"] for controllerName in genericControllers $routeProvider .when "/#{controllerName}/", action: 'confirmLogin' controller: 'GenericController' controllerName: controllerName templateUrl: "/static/templates/#{controllerName}.html" resolve: items : ["$q", "$route", "$http", ($q, $route, $http) -&gt; deferred = $q.defer() controllerName = $route.current.controllerName $http( method: "GET" url: "/api/#{controllerName}/" ) .success (response) -&gt; deferred.resolve(response.payload) .error (response) -&gt; deferred.reject(response.message) return deferred.promise ] $routeProvider .otherwise redirectTo: '/' action: 'checkStatus' ] appModule.controller "GenericController", ["$scope", "$route", "$http", "$cookies", "items", ($scope, $route, $http, $cookies, items) -&gt; $scope.items = items #etc .... ] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload