Questions tagged [angularjs-ng-init]

In AngularJS, the ngInit directive allows you to evaluate an expression in the current scope.

From Angularjs documentation:

The ngInit directive allows you to evaluate an expression in the current scope.
The only appropriate use of ngInit is for aliasing special properties of ngRepeat. Besides this case, you should use controllers rather than ngInit to initialize values on a scope.

Note: If you have assignment in ngInit along with $filter, make sure you have parenthesis for correct precedence:

<div ng-init="test1 = (data | orderBy:'name')"></div>

Usage

as attribute:

<ANY
  ng-init="expression">
...
</ANY>

as CSS class:

<ANY class="ng-init: expression;"> ... </ANY>
135 questions
0
votes
1 answer

Context dictionary from Django template to Angular

I am building a web app and I want to know what is the best and the safest way to pass a variable from a django context dictionary to Angular. I have access to a variable of the context dictionary from Django template. Should I use ng-init to pass…
0
votes
1 answer

How do I stop the select from losing it's selected value after any event on the page occurs?

When the page is first loaded, the select binds to the correct value (calculated by ng-init) but as soon as any button is clicked on the page, the select loses its selected value. I'm new to angularJS. What is the reason for the ng-model to be…
0
votes
1 answer

Angular JS - declaring function inside ng-init?

I have few queries. Pls find them below - 1) A function defined inside an ng-init like given below ng-init='function a() {}' errors out. Changing the syntax to variable declaration type or Instantly invoked also doesn't work. why? Since we can…
0
votes
1 answer

Why variable initialization is required in ng-init: AngularJS

I have started leaning AngularJS. In AngularJS if we have to initialize an element lets take an example of select: roles[] gets assigned in a subscribe of…
0
votes
1 answer

ng-init not working to inizialize data in combobox (angular)

I'm trying to initialize data in combobox, and I have tried every possible ways, but nothing:
iit2011081
  • 742
  • 8
  • 26
0
votes
2 answers

ng-init is not setting my default category in my select within my Angular app

I have the exact same problem as mentioned here: How to have a default option in Angular.js select box However none of the answers fix my issue below, I'm trying to get the first category to show up inside of the select:

Choose a tag…

Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
0
votes
0 answers

Loading data with ng-init

I have a problem loading data in three dropdowns in my html with ngInit angular directive. I call the method initAll() in my controller from ng-init. This function loads the list of values for three select elements but just the one for brands is…
Light1988
  • 77
  • 12
0
votes
4 answers

Set ng-init value of select-controller with Angular using disabled options

I can't get this to work: