我$watch
用来在数据加载时触发动画,这是一个使用的基本示例ng-show
HTML
<div ng-show="load"></div>
控制器
function myCtrl($scope, $timeout) {
$scope.load = true;
$timeout(function() {
$scope.users = [
{name: 'George', age: 20},
{name: 'Tom', age:21},
{name: 'Feeling', age:22}
];
$scope.load = false;
}, 1000);
$scope.addRow = function(){
$scope.users.push({name: 'New user', age: null});
};
}
指示
app.directive( 'afterLoadedAnimation', function() {
return {
scope : true,
link : function ( $scope, element, attributes ){
$scope.$watch( 'load', function ( newVal, oldVal ){
if( newVal !== oldVal ){
// Trigger the animation
}
});
}
});