1

Is it possible to use ternary operator in ng-init in AngularJS ?

Something like : <select ng-model="project" name="act" ng-options="act.user_id as act.user_display_name for act in actors" ng-init="isLoggedIn == true ? "" : act.user_id = credentials.user_id" ></select>

Steffi
  • 6,835
  • 25
  • 78
  • 123

1 Answers1

8

Yes, it's possible. Here's a very simple demo:

http://jsbin.com/wobayovi/1/edit?html,output

bencripps
  • 2,025
  • 3
  • 19
  • 27
  • Hey @bencripps, thanks. Seems work :) but very touchy huh ? What means (true === true) ? – Steffi Jul 24 '14 at 15:28
  • Haha I didnt mean anything by it-- I just wanted a very simple demo. True will always evaluate to true, you could change the ternary expression to anything you like. – bencripps Jul 24 '14 at 15:41