Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html data-ng-app="app">
  <head>
    <meta charset="utf-8">
    <title>%title%</title>
    <style type="text/css">
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
  </head>
  <body data-ng-controller="AppCtrl">
    <my-directive input="raw" on-compute="setComputed(computed)"></my-directive>
    <pre>{{ raw | json }}</pre>
    <pre>{{ computed | json }}</pre>
  </body>
</html>
 
(function (app, ng) {
  'use strict';
  app.controller('AppCtrl', ['$scope', function ($scope) {
    $scope.raw      = [1, 2, 3];
    $scope.computed = null;
    $scope.setComputed = function setComputed(computed) {
      $scope.computed = computed;
    };
  }]);
  app.directive('myDirective', function () {
    return {
      restrict: 'E',
      scope: {
        input:     '=?',
        onCompute: '&'
      },
      link: function (scope) {
        function compute(input) {
          return input.slice().reverse();
        }
        scope.$watch('input', function (nv) {
          scope.onCompute({
            computed: compute(nv)
          });
        });
      }
    };
  });
}(angular.module('app', []), angular));
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