【发布时间】:2015-06-11 09:00:04
【问题描述】:
如果我们不介意公然违反 MVC,这很容易做到,但是由于我正在努力学习如何使用 angular,所以我一直在为这种无害的小事情而烦恼。
我只想让div#thisShouldFade 在选择新事物时淡出,然后使用新数据淡入。
这是html:
<body ng-app="MyApp">
<div ng-controller="MyController as myCtrl">
<select ng-model="myCtrl.currentThing" ng-options="object.name for object in myCtrl.things">
<option value="">--choose a thing--</option>
</select>
<div id="thisShouldFade">{{myCtrl.currentThing.data}}</div>
</div>
</body>
和javascript:
angular.module("MyApp", [])
.controller("MyController", function(){
this.things = [
{ name: "Thing One", data: "This is the data for thing one" },
{ name: "Thing Two", data: "This is the data for thing two" },
{ name: "Thing Three", data: "This is the data for thing three" }
];
this.currentThing = null;
})
和笨蛋:
http://plnkr.co/edit/RMgEOd6nrT9lFQlslDR0?p=preview
我尝试了许多不同的方法,使用 ngAnimate 设置具有 CSS 过渡的类,但根本问题似乎是模型会立即更改,因为它绑定到 SELECT。
任何人都有一个好的 angular-iffic 策略?我宁愿把 jQuery 放在一边。也就是说,这是一个 jQuery plunk,它显示了所需的效果:
【问题讨论】:
-
看看这个问题和链接的视频。 stackoverflow.com/questions/13083644/…
-
@isherwood 您的链接和相应的视频使用了已弃用的方法。 “更新”链接试图说明 angular 1.2 的基于类的较新动画,提供了一种可怕的、非常无角度的方法,以及我们都试图避免的硬编码 setTimeouts。
标签: javascript angularjs css-animations