?
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
ngBind
屬性告訴Angular使用所給表達式的值替換指定HTML元素的文本內(nèi)容,并且在表達式的值改變時更新文本內(nèi)容。
一般情況下,你不需要使用ngBind
指令,可以使用像{{ expression }}
形式的雙花括號來替換,達到同樣的效果并且只需少量命令。
使用 ngBind
替換 {{ expression }}
是更好的方法,在處于Angular編譯前的原生狀態(tài)時的模板被瀏覽器立即顯示時。由于ngBind
只是一個元素屬性,當頁面載入時它創(chuàng)建的綁定對用戶是不可見。
這個問題的另一個替代解決方案是使用 ngCloak 指令。
<ANY
ng-bind="">
...
</ANY>
<ANY class="ng-bind: ;"> ... </ANY>
參數(shù) | 類型 | 詳述 |
---|---|---|
ngBind | expression | 可求值表達式。 |
在實時預(yù)覽文本框輸入名稱,文本框的下方會立即刷新問候信息。
<script>
angular.module('bindExample', [])
.controller('ExampleController', ['$scope', Function($scope) {
$scope.name= 'Whirled';
}]);
</script>
<div ng-controller="ExampleController">
Enter name: <input Type="text" ng-model="name"><br>
Hello <span ng-bind="name"></span>!
</div>
protractor.jsit('should check ng-bind', Function() {
var nameInput = element(by.model('name'));
expect(element(by.binding('name')).getText()).toBe('Whirled');
nameInput.clear();
nameInput.sendKeys('world');
expect(element(by.binding('name')).getText()).toBe('world');});