1

I have a selection list that I get from the controller, written like this:

<select class="input form-control"
    id="animationTime"
    ng-options="item as item.label for item in aniCon.timeOptions track by item.id"
    ng-model="aniCon.popupTime"
    ng-init="aniCon.popupTime = aniCon.timeOptions[{{aniCon.popupTime.id}}]">
</select>

This causes a parse error here: aniCon.timeOptions[{..., a value is expected not {{..

The thing is that this value {{aniCon.popupTime.id}} is seen as 3 when the page loads and then the html is correct: aniCon.popupTime = aniCon.timeOptions[3]

So I want to ignore this parse error somehow.

Tushar
  • 85,780
  • 21
  • 159
  • 179
ganjan
  • 7,356
  • 24
  • 82
  • 133
  • 1
    Generally, you should be initializing values in your controller, then you wouldn't have to worry about parsing through ng-init. – Patrick Nov 09 '15 at 14:52

1 Answers1

1

Remove the brackets. For Angular directives, there is no need of using expressions

ng-init="aniCon.popupTime = aniCon.timeOptions[aniCon.popupTime.id]">

As @Patrick has said in comment, you should move the code of initialisation to the controller.

$scope.aniCon = {};
// Get the object values here
$scope.aniCon.popupTime = $scope.aniCon.timeOptions[$scope.aniCon.popupTime.id];
Tushar
  • 85,780
  • 21
  • 159
  • 179