javascript - how to set ng-model Value via ng-init or value tag -


i want set ng-model value. tried ng-init , value tag.

my code:

init

{{formobject.consultantid}}  // value prints  <input type="hidden" data-ng-model="formobject.consultant.id" data-ng-init="formobject.consultant.id=formobject.consultantid">  {{formobject.consultant.id}} // no data prints 

value

{{formobject.consultantid}}  // value prints  <input type="hidden" data-ng-model="formobject.consultant.id" value="{{formobject.consultantid}}">  {{formobject.consultant.id}} // no data prints 

this works me

<input type="hidden" data-ng-model="formobject.consultant.id" data-ng-init="formobject.consultant.id='test'">  {{formobject.consultant.id}} // prints test 

whats wrong in code ? how initialize value model ?

edit

i found issue. code works me in normal html form. above codes in modelform(directive).

you should change {{formobject.consultantshare.consultant.id}} {{formobject.consultant.id}} (to op's edit, removed)

take @ this

var app = angular.module('myapp', []);  app.controller('controller', function ($scope) {      $scope.formobject = {};      $scope.formobject.consultant = {};      $scope.formobject.consultantid = "254";    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  <div ng-app='myapp' ng-controller="controller">{{formobject.consultantid}} // value prints      <input type="hidden" data-ng-model="formobject.consultant.id" data-ng-init="formobject.consultant.id=formobject.consultantid" />{{formobject.consultant.id}}      <br/>{{formobject.consultantid}} // value prints      <input type="hidden" data-ng-model="formobject.consultant.id" value="{{formobject.consultantid}}"/>{{formobject.consultant.id}}   </div>


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -