javascript - Changing CSS from AngularJS -
dom changes angularjs controllers not practice. in application, after clicking on link, changing class of html element inside ngview. intended behaviour is, have 3 divs, , changing if middle 1 shown or not. doing controller. have read, doing dom manipulation should done in directive, mind not broad enough find solution. please, if have suggestion, glad.
use ng-class.
e.g:
http://jsfiddle.net/rd13/ettzj/75/
app = angular.module('myapp', []); app.directive("click", function () { return function(scope, element, attrs) { element.bind("click", function() { scope.boolchangeclass = !scope.boolchangeclass; scope.$apply(); }); }; });
some html:
<div id="page"> <div>one</div> <div ng-class="{'my-class':boolchangeclass}">two</div> <div>three</div> <button click>click me</button> </div>
when click button, class of center div change depending on boolen value set within scope.
Comments
Post a Comment