$interval(function() {
var count = $scope.announcements.length;
for(var i=0;i<count;i++) {
if($scope.announcement == $scope.announcements[i].description) {
if(i==count-1) {
$scope.announcement = $scope.announcements[0].description;
if($scope.announcement.length >= 100) {
$scope.readmore = true;
$scope.short_ann = $scope.announcement.substr(0,85);
}
break;
} else {
$scope.announcement = $scope.announcements[i+1].description;
if($scope.announcement.length >= 100) {
$scope.readmore = true;
$scope.short_ann = $scope.announcement.substr(0,85);
}
break;
}
}
}
}, 5000);
$ scope.announcement每5秒更新一次,我想要一个小动画,同时改变这个的ng-bind
答案 0 :(得分:1)
创建一个指令,监视属性的值更改并执行动画。
例如:
app.directive('flash', ['$animate',
function($animate) {
return {
link: function(scope, element, attrs) {
scope.$watch(attrs.flash, function(newValue, oldValue) {
if (newValue === oldValue) return;
$animate.addClass(element, 'flash').then(function() {
element.removeClass('flash');
});
});
}
};
}
]);
用法:
<p flash="announcement" class="animated">{{announcement}}</p>
如果您知道将使用ng-bind
,则替代用法是:
<p flash ng-bind="announcement" class="animated"></p>
使用第二个版本,您需要观看attrs.ngBind
而不是attrs.flash
:
scope.$watch(attrs.ngBind, ...
请注意,此示例使用ngAnimate
和animate.css
来执行动画。
答案 1 :(得分:0)
将ng-model用于p标签以显示实际数据,并使用ngAnimate或smth else ...
<p ng-model="announcement">{{announcement}}</p>