Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用范围变量中的值初始化AngularJS中的输入表单_Angularjs - Fatal编程技术网

使用范围变量中的值初始化AngularJS中的输入表单

使用范围变量中的值初始化AngularJS中的输入表单,angularjs,Angularjs,如何将表单初始化为AngularJS中其他$scope变量的值? 我知道我必须使用nginit来实现这一点,但是我必须将其初始化为变量中的值,而不是将其初始化为值 我有$scope.User包含用户的所有详细信息,因此当数据返回时,我希望将其反馈到相应的字段中。例如,$scope.User.FirstName被输入到FirstName输入字段中 <label>FirstName:</label> <input type="text" id="FirstName" r

如何将表单初始化为AngularJS中其他
$scope
变量的值? 我知道我必须使用
nginit
来实现这一点,但是我必须将其初始化为变量中的值,而不是将其初始化为值

我有
$scope.User
包含用户的所有详细信息,因此当数据返回时,我希望将其反馈到相应的字段中。例如,
$scope.User.FirstName
被输入到FirstName输入字段中

<label>FirstName:</label>
<input type="text" id="FirstName" required ng-model="newUser.FirstName" ng-init="newUser.FirstName='User.FirstName'"/>
FirstName:

HTML元素必须定义如下

<input type="text" ng-model="firstname">
这将确保文本框在HTML中显示一个值:

<input type="text" ng-model="User.firstname ">
<input type="text" ng-model="User.lastName ">
//other html elements

不要使用
ng init
,这是控制器的作业。
<input type="text" ng-model="User.firstname ">
<input type="text" ng-model="User.lastName ">
//other html elements
$scope.User= {
  firstname : 'my first name',
  lastName : 'my last name',
  //..other data
}