Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
169
rated 0 times [  174] [ 5]  / answers: 1 / hits: 84560  / 10 Years ago, wed, may 28, 2014, 12:00:00

So I'm wondering how I can declare multiple values within a single ng-init, without having to create some weird hash, that then I need to always access specifically.



so basically I would like



<div ng-init=a = 1, b = 2>{{a}}</div>


and I'm saying that I would like to avoid having to do



<div ng-init=unecessary_bs = {a: 1, b: 2}>{{unecessary_bs.a}}</div>


However the reasonable :



<div ng-init=a = 1, b = 2>{{a}}</div>


doesn't seem to work.



Anticipated Thanks


More From » angularjs

 Answers
38

Use a function, way more readable:



ng-init=init()


And:



$scope.init = function() {
$scope.a = 1;
$scope.b = 2;
}


Or, if you must, separate inline variables with a semi-colon:



ng-init=a = 1; b = 2

[#70819] Monday, May 26, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mira

Total Points: 460
Total Questions: 108
Total Answers: 99

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
mira questions
;