我正在尝试将动画添加到控制器正在侦听的服务中推送到数组中的新对象,然后使用ng-repeat将其添加到视图中。如何添加动画而不是只显示新对象?
以下是我的视图、控制器和服务的代码。
查看:
<div>
<h3>Add a quote:</h3>
<input type="text" ng-model="newQuote.text" placeholder="Quote...">
<input type="text" ng-model="newQuote.author" placeholder="Author...">
<button ng-click="addQuote()">Add</button>
</div>
<h1>Quotes</h1>
<div ng-repeat="thisData in someData | filter:searchThis">
<div id="{{thisData.id}}" class="quotes">
<p class="quote">"{{thisData.text}}"<br>-{{thisData.author}}</p>
<button class="deleteButton" ng-class="{on:state}" ng-click="deleteQuote(thisData.text)">X</button>
</div>
</div>控制器:
$scope.getData = function(){
$scope.someData = dataService.getData()
}
$scope.getData()
$scope.newQuote = {}
$scope.addQuote = function(){
dataService.addData($scope.newQuote)
$scope.newQuote = ""
}服务:
var quotes = [
{ id: 0, text: 'Life isn\'t about getting and having, it\'s about giving and being.', author: 'Kevin Kruse'},
{ id: 1, text: 'Whatever the mind of man can conceive and believe, it can achieve', author: 'Napoleon Hill'},
{ id: 2, text: 'Strive not to be a success, but rather to be of value.', author: 'Albert Einstein'},
{ id: 3, text: 'Two roads diverged in a wood, and I took the one less traveled by, And that has made all the difference.', author: 'Robert Frost'},
{ id: 4, text: 'The most difficult thing is the decision to act, the rest is merely tenacity.', author: 'Amelia Earhart'},
{ id: 5, text: 'Life is what happens to you while you\'re busy making other plans.', author: 'John Lennon'},
{ id: 6, text: 'What even is a jQuery?', author: 'Tyler S. McGinnis'}
];
this.getData = function(){
return quotes
}
this.addData = function(someObj){
if (someObj.text && someObj.author){
quotes.unshift(someObj)
} else {
return "Error"
}
}发布于 2015-05-07 10:58:02
使用模块ngAnimate,您有两个选择:
1)对类.ng-enter和.ng-enter.ng-enter-active使用基于css的动画
2)使用基于js的动画
我用CSS动画here创建了一个示例。
https://stackoverflow.com/questions/30090608
复制相似问题