Looks like you just want to collapse something with CSS3 transitions?
Well, you can do it, but the controller is the wrong place for this. You must do this using directives or in a custom directive. Fortunately, you can do this with native Angular directives such as ng-class.
HTML:
<button ng-click="open = !open">Toggle</button> <div ng-class="{ showMe: open }" class="collapsable"> <h3>This should collapse</h3> </div>
And most importantly, your CSS:
.collapsable { display: inline-block; overflow: hidden; height: 0; transition: height 1s; -webkit-transition: height 1s; -moz-transition: height 1s; -o-transition: height 1s; } .collapsable.showMe { height: 100px; }
And the pluker is working.
It is important to note that CSS3 transitions will not work in all browsers. Especially in IE. In the end, I think you will probably be better off using a plugin that someone else has already done, and then using it in a custom directive that looked at some boolean value.
I hope this helps.
EDIT
height: auto does not work with CSS transitions (at least at the time of publication). So thatโs why you really want to use another userโs plugin rather than reinvent the wheel. Even if it's just a jQuery animate () method. The pseudoex code for wrapping your own directive would be something like this: (assuming you're using jQuery)
app.directive('collapseWhen', function () { return function(scope, elem, attr) { scope.$watch(attr.collapseWhen, function(val) { var clone = elem.clone().appendTo('body'); var h = clone.height(); clone.remove(); scope.animate({ height: (val ? h : 0) + 'px' }, 1000); } } });
and then you will use it like:
<button ng-click="foo = !foo">Toggle</button> <div collapse-when="foo">
Again, the psuedo code above, I have no idea whether this will work or not, it's just to give you the idea to follow if you really want to quit your own.