Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body ng-app="app">
  <div ng-controller="NavController">
    <h1 ng-bind-html="currentTitle()"></h1>
  </div>
  <div ng-controller="DetailCtrl">
    <button ng-click="updateCurrentTitle()">Update CurrentTitle</button>
  </div>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
  <script>
    var app = angular.module('app', [])
    .controller('NavController', function($http, $sce, $scope, WorkService) {
       $scope.works = [];
        $http({method: 'GET', url: '/api/v1/work'}). //collects all works
        success(function(data, status, headers, config) {
          $scope.currentTitle = WorkService.getCurrentTitle;
        }).
        error(function(data, status, headers, config) {
          $scope.currentTitle = WorkService.getCurrentTitle;
        });
    })
    .controller('DetailCtrl', function($scope, $http, $sce, WorkService) {
      $scope.updateCurrentTitle = function(){
        console.log('get detail');
        $http({method: 'GET', url: '/api/v1/work2/'}).
          success(function(data, status, headers, config) {
              $scope.activateButton($routeParams.workId);
              WorkService.setCurrentTitle(data.title)
          }).
        error(function(data, status, headers, config) {
          WorkService.setCurrentTitle('Text set by DetailController');
        });
      }
    }).service('WorkService', ['$sce', function($sce){
        var currentTitle= $sce.trustAsHtml('dada');
        return {
          getCurrentTitle: function(){ return currentTitle; },
          setCurrentTitle: function(value){ currentTitle = $sce.trustAsHtml(value);}
        };
    }]);
  </script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
jerradepro
0viewers