Angular: directive with & 14326077

http://angularjs.org/

by mrajcok

HTML

<div ng-controller="MyCtrl">
  <div ng-show="showApp == true" show-app="{{showApp}}" ngx-Onshow="showAppBar()"> 
  </div>
  <a ng-click="showIt()">show app bar</a>
</div>

JavaScript

var myApp = angular.module('myApp', []);

myApp.directive('ngxOnshow', function () {
  return {
    restrict: 'A',
    scope: {
      showApp: '@',
      ngxOnshow: '&'
    },
    link: function (scope, element, attrs) {
      console.log("inside link function")
      attrs.$observe('showApp', function (newValue) {
        newValue === "true" && scope.ngxOnshow()
      })
    }
  };
});

function MyCtrl($scope) {
  $scope.showApp = false;
  $scope.showIt = function () {
    $scope.showApp = true;
  }
  $scope.showAppBar = function () {
    console.log('showAppBar')
  }
}