Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html ng-app="boo">
<head>
<meta name="description" content="anguler directive compile" />
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <div ng-controller='myController'>
    <div ng-show="states.currentState === 'A'">
        <a ng-click="doStuff('B')">Do stuff and show B</a>
    </div>
    <div ng-show="states.currentState === 'B'">
        displaying this div if the currentState is B
    </div>
    {{states.currentState}}
</div>
</body>
</html>
 
var m = angular.module("boo", []);
m.controller('myController', ['$scope', function($scope){
  var states = ['A', 'B'];
  $scope.states = states;
  $scope.states['currentState'] = $scope.states['currentState'] || 'A';
  $scope.doStuff = function(stateToShow) {
    console.log(stateToShow);
    //doing stuff
    $scope.states.currentState = stateToShow;
  };
}]);
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers