Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set a default value to an input with the ng-model in my template?

Tags:

angularjs

I try to achieve this:

<input name="formkey"
       ng-model="formkey"
       value="1_4bKU-Be3K4sMuoQTDHfz7uMqGd9N9fU6bGd1EjEu8s"
>

or:

<input type="hidden" 
       name="formkey"
       ng-model="formkey" 
       value="1_4bKU-Be3K4sMuoQTDHfz7uMqGd9N9fU6bGd1EjEu8s"
>

The input is empty when I look at it in a browser. If I remove ng-model="formkey" it works, so I assume the empty formkey-value overwrites my value.

I know I can add values to the scope with javascript. But I use this same javascript in a lot of different views, so I would much prefer to add the value in my view somehow. Is it at all possible?

like image 734
Himmators Avatar asked Dec 18 '13 09:12

Himmators


1 Answers

ng-init should do the trick:

<input ng-init="formkey='Your default value'" />
like image 68
Atropo Avatar answered Sep 18 '22 06:09

Atropo