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
2
votes
2 answers

Set selected value of select menus

I have three select menu that bind to each other and want to set selected value of two select menus. Value that I want to set comes with scope. I try ng-init but that didn't work. Working Plunker
abhi05b
  • 103
  • 2
  • 7
2
votes
2 answers

Syntax danger: Token '}' is unexpected, expecting [:] at column 35 of the expression [yourSelectRadio={item.Polarisation}]

error : Error: [$parse:syntax] Syntax danger: Token '}' is unexpected, expecting [:] at column 35 of the expression [yourSelectRadio={item.Polarisation}] starting at…
Footabll.My.Life
  • 155
  • 2
  • 4
  • 13
2
votes
1 answer

What to do to fix race condition when setting ng-init from a cookie

I need to access to data with angularjs, as one would do with a simple static
in a context where the ng-init attribute has to be set from data coming from a cookie. This pretty much should work, however, my partial…
Stéphane de Luca
  • 12,745
  • 9
  • 57
  • 95
1
vote
4 answers

Angularjs - nested ng-repeat global index

I have next template:
{{something}}
And model: $scope.order = { Suppliers:…
David Levin
  • 6,573
  • 5
  • 48
  • 80
1
vote
2 answers

Using ng-init to send data from a ng-repeat to another controller

I have a html file that runs a ng-repeat and then each item in that ng-repeat will generate a template which also has it's own controller On the html file I have something like:
N.Car
  • 492
  • 1
  • 4
  • 14
1
vote
1 answer

how to add days to date variable on every ng-repeat loop in angularjs

I have set date variable in "ng-init" directive and i want to add days to this date variable on every ng-repeat loop like below:
nativegrip
  • 892
  • 10
  • 20
1
vote
1 answer

Which element does myVar bind to? Problems with `ng-init`

I'm wondering what's happening behind the scenes when using ng-init. Sometimes ng-init does some unexpected things, and I have a hard time debugging. Let's say I have the following structure:
Jeffrey Roosendaal
  • 6,872
  • 8
  • 37
  • 55
1
vote
1 answer

ng-init in Select is not working in angularJS

I have a Select element like this Now i want to set the initial…
Lijin Durairaj
  • 4,910
  • 15
  • 52
  • 85
1
vote
0 answers

how to set default value after ng-options completed?

assume that this is my controller: function MainController(BaseInformation, baseInformationConstants) { var vm = this; getGenders(); function getGenders() { vm.genders = BaseInformation.list({headerId:…
Rasool Ghafari
  • 4,128
  • 7
  • 44
  • 71
1
vote
1 answer

I am using MVC 4 and angularjs in this actually I want to call an angular js function on page load

i want to invoke angularjs function (DeptSpecific) on page load and am passing ID as the parameter which is hard coded. And that i am passing via ng-init="DeptSpecific('1')". I am learning angularjs please suggest me how to call a function and pass…
1
vote
0 answers

How can I set the first accordion item in the ngRepeat to be open while the rest are not?

I'm creating a list of tables with collapsible tbodys. This code works fine but I want to have the first tbody open on default. I've tried ng-init="showReports0" on the table tag, but this doesn't work. I've also tried to predefine…
Christian Hill
  • 378
  • 1
  • 3
  • 17
{{x.JobName}} {{$index+1}}){{y.Location}} …
user6769704
1
vote
1 answer

AngularJS - Initialize form data based on value

I am trying to add edit functionality to my app. In one view, I have a button that brings you to the edit page. The value selectedMission.key is used to determine what to…
user3646037
  • 293
  • 1
  • 6
  • 16
1 2
3
8 9