Is it not possible to use strongly typed objects in asp.net mvc to initialize ng-model properties as currently the view value is getting cleared as soon as ng-model property is getting bind to view.I know it will work if I initialize that value form model but that would mean I will have to make a get request just to pull the model value ,but what if I want to leverage existing strongly typed model binding feature of asp.net mvc ??
2 Answers
You can make you use of ng-init. For example you have:
<input type="text" ng-model="name">
You can use it as:
<input type="text" ng-model="name" ng-init="name='@Model.Name'">
Which on the client side will get converted to:
<input type="text" ng-model="name" ng-init="name='Abdel'">
And you will be able to use it... Hope this helps!
1 Comment
Mayank Singh
yes ng-init can be one of the option but I want a generic and more cleaner way of doing this , so that view takes the owners ship of initializing model's property , basically I don't want to repeat this for each model property. - @Abdel Raoof