AngularJS:如何将默认值设置为ng-model =" searchText&quot ;? [英] AngularJS: How to set default value to ng-model="searchText"?

查看:106
本文介绍了AngularJS:如何将默认值设置为ng-model =" searchText&quot ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将默认值设置为ng-model =searchText。这里是我使用的代码

< input ng-model =searchTextvalue =can you see me/> p>

任何人都可以帮我解决这个问题吗? 第一个解决方案:是简单地初始化控制器中的searchText。

  App.controller('mainController',['$范围',函数($范围){
$ scope.searchText =你能看见我;
}]);

第二种解决方案:是使用ng-init insteat value p>

 < input ng-model =searchTextng-init =searchText ='can you see me'>< /输入> 


I am unable to set a default value to ng-model="searchText". Here is the code I am using
<input ng-model="searchText" value="can you see me" />

Can anyone help me with this?

解决方案

1st Solution: is to simply init the searchText in the controller.

App.controller('mainController',['$scope', function($scope) {
   $scope.searchText  = "can you see me";
}]);

2nd Solution: is to use ng-init insteat of value

<input ng-model="searchText" ng-init="searchText ='can you see me'"></input>

这篇关于AngularJS:如何将默认值设置为ng-model =&quot; searchText&quot ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆