?
Ce document utilise Manuel du site Web PHP chinois Libérer
ngBindTemplate
指令使元素的文本內(nèi)容會被替換為 ngBindTemplate
屬性中給出的模板內(nèi)容。不像 ngBind
, ngBindTemplate
可以使用 {{
}}
表達式。這個指令主要用于一些HTML元素 (像TITLE和OPTION)不能包含SPAN元素的狀況下。
<ANY
ng-bind-template="">
...
</ANY>
參數(shù) | 類型 | 詳述 |
---|---|---|
ngBindTemplate | string | template of form {{ expression }} to eval. |
試下這里:在文本框輸入文本并查看問候信息的變化。
<script>
angular.module('bindExample', [])
.controller('ExampleController', ['$scope', Function ($scope) {
$scope.salutation = 'Hello';
$scope.name= 'World';
}]);
</script>
<div ng-controller="ExampleController">
Salutation: <input Type="text" ng-model="salutation"><br>
Name: <input Type="text" ng-model="name"><br>
<pre ng-bind-template="{{salutation}} {{name}}!"></pre>
</div>
protractor.jsit('should check ng-bind', Function() {
var salutationElem = element(by.binding('salutation'));
var salutationInput = element(by.model('salutation'));
var nameInput = element(by.model('name'));
expect(salutationElem.getText()).toBe('Hello World!');
salutationInput.clear();
salutationInput.sendKeys('Greetings');
nameInput.clear();
nameInput.sendKeys('user');
expect(salutationElem.getText()).toBe('Greetings user!');});