我这里有一个html文本框。它有一个ng-model
和一个初始值。问题是,当存在ng模型时,初始值不会显示,我需要ng-model和文本框的初始值。
HTML:
<input type="text"
ng-model="selPcode"
name="missionId"
value="123">
JS:
$scope.setPcode = function(site){
$scope.selPcode = site.id};
有人可以建议如何在文本框中显示值并保持ng-model
存在吗?提前谢谢。
答案 0 :(得分:0)
在控制器范围内为ng-model设置初始值。像/**
@param context : it is the reference where this method get called
@param docPath : absolute path of file for which broadcast will be send to refresh media database
**/
public static void refreshSystemMediaScanDataBase(Context context, String docPath){
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(new File(docPath));
mediaScanIntent.setData(contentUri);
context.sendBroadcast(mediaScanIntent);
}
这样的东西。将它设置为您的价值。这样,它最初会显示,然后您也可以更改它。
答案 1 :(得分:0)
答案 2 :(得分:0)
使用ng-init而不必触摸控制器并保持HTML中的代码可读,就像使用Inputbox标准使用的value =语法一样。 Plunkr here
此处示例(控制器为语法):
<div ng-controller="myController as my">
<h1>Hello {{my.name}}</h1>
<input type="text"
ng-init="my.selPcode=123"
ng-model="my.selPcode"
name="missionId">
</div>
控制器:
myApp.controller('myController', function($scope) {
this.name = "Gene";
});