Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Correct minify-able syntax when using resolve with controllers

I'm using the resolve functionality with a couple of controllers to fetch some data before the rendering of a new view kicks in like this:

HomeCtrl.resolve = {     pictures: function(Picture) {         return Picture.getall();     }  }; 

How do I write this so the Picture-service, that is passed as an argument, doesn't get overwritten when minified?

like image 908
acrmuui Avatar asked Apr 02 '13 11:04

acrmuui


People also ask

How do you minify a project in AngularJS?

Alternatively, you can use ng-annotate npm package in your build process to avoid this verbosity. Instead of using this more verbose syntax you can use ngmin and a build tool (like Grunt) before you run minification. That way you can minify properly but also use either dependency injection syntax.

What is $inject in AngularJS?

Dependency Injection in AngularJS can be defines as the software design pattern which defines the way the software components are dependent on each other. AngularJS provides a set of components that can be injected in the form of dependencies such as factory, value, constant, service, and provider.

How do I inject a module in AngularJS?

Injecting a value into an AngularJS controller function is done simply by adding a parameter with the same name as the value (the first parameter passed to the value() function when the value is defined). Here is an example: var myModule = angular. module("myModule", []); myModule.

Which of the following components can be injected as dependency in AngularJS?

26) Which of the following components can be injected as a dependency in AngularJS? Answer: D is the correct answer. The "Application Module" can be injected as a dependency in AngularJS.


1 Answers

You can inject the dependencies using the following pattern, it is minification proof

HomeCtrl.resolve = {     pictures : ['Picture', function(Picture) {                 return Picture.getall();             }] }; 
like image 61
Arun P Johny Avatar answered Sep 29 '22 20:09

Arun P Johny