?
Ce document utilise Manuel du site Web PHP chinois Libérer
可以進行angular數(shù)據(jù)綁定的標(biāo)準(zhǔn)HTML文本輸入框。
<input Type="text"
ng-model=""
[name=""]
[required=""]
[ng-required=""]
[ng-minlength=""]
[ng-maxlength=""]
[ng-pattern=""]
[ng-change=""]
[ng-trim=""]>
參數(shù) | 類型 | 詳述 |
---|---|---|
ngModel | string | 聲明用于數(shù)據(jù)綁定的Angular表達式。 |
name (可選)
|
string | 發(fā)布到表單下的控件的屬性名稱。 |
required
(可選)
|
string | 如果值沒有輸入,則設(shè)置 |
ngRequired
(可選)
|
string | 當(dāng)ngRequired表達式等于true時,添加 |
ngMinlength
(可選)
|
number | 如果值短于minlength則設(shè)置 |
ngMaxlength
(可選)
|
number | 如果值長于maxlength則設(shè)置 |
ngPattern
(可選)
|
string | 如果值不匹配正則表達式則設(shè)置 |
ngChange
(可選)
|
string | Angular表達式,當(dāng)輸入元素通過用戶交互方式發(fā)生輸入變化時會執(zhí)行這個表達式。 |
ngTrim
(可選)
|
boolean | 如果設(shè)置為false,Angular將不自動去除輸入內(nèi)容的空格。 |
<script>
angular.module('textInputExample', [])
.controller('ExampleController', ['$scope', Function($scope) {
$scope.text = 'guest';
$scope.word = /^\s*\w*\s*$/;
}]);
</script>
<form name="myForm" ng-controller="ExampleController">
Single word: <input Type="text" name="input" ng-model="text"
ng-pattern="word" required ng-trim="false">
<span class="error" ng-show="myForm.input.$error.required">
Required!</span>
<span class="error" ng-show="myForm.input.$error.pattern">
Single word only!</span>
<tt>text = {{text}}</tt><br/>
<tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/>
<tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/>
<tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
<tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
</form>
protractor.jsvar text = element(by.binding('text'));var valid = element(by.binding('myForm.input.$valid'));var input = element(by.model('text'));
it('should initialize to model', Function() {
expect(text.getText()).toContain('guest');
expect(valid.getText()).toContain('true');});
it('should be invalid if empty', Function() {
input.clear();
input.sendKeys('');
expect(text.getText()).toEqual('text =');
expect(valid.getText()).toContain('false');});
it('should be invalid if multi word', Function() {
input.clear();
input.sendKeys('hello world');
expect(valid.getText()).toContain('false');});