I have a problem with ng-binding locator in Protractor code:
<h1 class="blackText ng-binding">some_link</h1>
I tried to use:
element(by.binding('some_link')).click();
Run Code Online (Sandbox Code Playgroud)
但它找不到任何东西.
This works:
element(by.cssContainingText('.ng-binding', 'some_link')).click();
Run Code Online (Sandbox Code Playgroud)
但我想使用绑定定位器.
有任何想法吗 ?
为什么这个小角度模块在ng-bind更改属性时无法更新视图?
<body ng-app="bindExample">
<script>
angular.module('bindExample', [])
.controller('ExampleController', ['$scope', function($scope) {
var vm = this;
vm.name = 'Whirled';
window.setInterval(function(){ vm.name = 'Jon';}, 5000);
}]);
</script>
<div ng-controller="ExampleController as vm">
Hello <span ng-bind="vm.name"></span>!
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
我期待在5秒之后输出Hello Jon因它保持不变而改变Hello Whirled.为什么是这样?我还需要做其他事吗?
我有一个函数getData,它只增加var计数器的值.
每当发生增量时,我都希望angular能够自动更新div中的内容
我尝试过ng-bind,但只有点击表单元素才有效.
enquire.controller('DisplayEnquiries', function($scope){
$scope.getData = function(){
console.log('Run ' + $scope.counter);
$scope.counter;
if($scope.counter == undefined || $scope.counter == null){
$scope.counter = 1
$scope.counter++;
}
else{
$scope.counter++;
}
console.log('Execute ' + $scope.counter);
$scope.count = $scope.counter;
}
setInterval($scope.getData, 1000);
});
Run Code Online (Sandbox Code Playgroud)
HTML
<div class="col-sm-5" ng-controller="DisplayEnquiries">
<h4>Unread User Queries</h4>
<p>
Count : <span ng-bind="count"></span>
</p>
</div>
Run Code Online (Sandbox Code Playgroud) 我ng-bind='data'通过指令将属性添加到元素中
myApp.directive('myDiv', function() {
return {
restrict: 'E',
link: function($scope, element, attrs) {
element.html('<div ng-bind="data">me</div>');
} }; });
function MyCtrl($scope) {
$('#click').click(function() {
$scope.data = 'change';
}); }
Run Code Online (Sandbox Code Playgroud)
但是ng-bind没有按预期工作.
ng-bind当两个冒号用双冒号连接时,我们如何使用?
<title ng-bind="::AppConfig.SITE_TITLE + ::AppConfig.PAGE_TITLE"></title>
Run Code Online (Sandbox Code Playgroud)
上面的代码返回此错误:
Error: [$parse:syntax] Syntax Error: Token ':' not a primary expression at column 24 of the expression [AppConfig.SITE_TITLE + ::AppConfig.PAGE_TITLE] starting at [::AppConfig.PAGE_TITLE].
Run Code Online (Sandbox Code Playgroud)
请注意,这工作正常:
<title ng-bind="::AppConfig.SITE_TITLE + ' | This is page title'"></title>
Run Code Online (Sandbox Code Playgroud) 我有这段代码可以正常工作,并将从控制器接收到的数据显示到绑定中。但是,我试图将服务器数据设置为string.empty,并且希望此默认文本“ Your name”会出现,但事实并非如此。如果服务器返回空字符串,我希望显示默认文本。
<label for="name" class="label-proj" ng-bind="ctrl.name">Your name</label>
Run Code Online (Sandbox Code Playgroud)