How do you use the Angular . run directive?

Asked

Viewed 1,197 times

-3

How the directive is used .run angularjs?

  • 2

    As a basic rule, I consider a question of poor quality whose text is exactly the same as the title. And, remembering, greetings and thanks are considered noisy: vine "Ain’t no blah blah blah" in the [tour]

1 answer

2

var app = angular.module('aplicacao', ['highcharts-ng']);

app.run(function($rootScope) {
    ...     
});

Explaining:

  var app = angular.module('aplicacao', ['highcharts-ng']);

Creates an angular module called 'application' that injects the dependency of 'highcharts-ng''.

app.run(function($rootScope) {

It is the starting point of your application. As a comparison, it is equal to the main(args) of java/c#.

And inside it you will write your code with the desired functions (:

  • Okay Pedro, But what if you want to start a global variable on it? Inside the function?

  • Through $rootScope, as can be done in any other service, controller, etc..

  • 1

    Declare inside app.run(Function() { its global variable like any other variable in Javascript (var i = 0;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.