Angular's Yeoman application works fine until I add ['ngResource'] and then it freezes

I created an AngularJS application with "yo angular", launched "grunt server -force" and hit the success screen of "Allo, Allo".

When I added ['ngResource'] as shown below, it seems to freeze ... or at least nothing else displays in the browser.

We are trying to add $ resource as a parameter to the function .... ee tried to use the resource, but no luck. I do not see errors in the web console. We checked that angular -resource.js is listed in / angular -resources components.

It sounds like a dumb beginner, but she got stuck.

'use strict';
angular.module ('a3App', ['ngResource'])
  .factory ('myService', function () {
  var foo = 42;
  return {
    someMethod: function () {
       return foo;
    }
   };
});
+5
source share
3 answers

Got the answer (or at least understanding) from the book Green and Seshadri AngularJS.

The angular.module operator works in two modes: configuration and startup. The 'ngResource' statement works fine with the configuration:

angular.module ('a3App', ['ngResource']). config (function ($ routeProvider) {
  $ routeProvider
    .when ('/', {
     templateUrl: 'views / main.html',
     controller: 'MainCtrl'
   })
   .otherwise ({
     redirectTo: '/'
   });
});

Job

but put the same statement in angular.module (...). factory statement, and it fails / hangs silently (because .factory is a start, not a configuration instruction):

angular.module('a3App', ['ngResource']).factory('myService', function($resource) {
...

6456 Kindle AngularJS ( " " 7). ( , ).. / .

+6

, . AngJS , ['ngResource'] factory.

, :

angular.module('a3App', ['ngResource']).factory('myService', function($resource) {
...

:

angular.module('a3App').factory('myService', function($resource) {
...

json rest api.

+6

.

angular.module('a3App', ['ngResource', 'another.dependency']). config() < - , run(), config(), , /// ..

angular.module ('a3App'). factory ('factoryName', function) <--- will work to create the component, does not need dependencies again, they have already been declared using the module.

0
source

All Articles