2013-12-10 76 views
1

是否可以使用嵌套的角度指令的打字稿?嵌套的角度指令與打字稿

http://jsfiddle.net/mrajcok/StXFK/

<div ng-controller="MyCtrl"> 
    <div screen> 
    <div component> 
     <div widget> 
      <button ng-click="widgetIt()">Woo Hoo</button> 
     </div> 
    </div> 
</div> 
</div> 

下面的JavaScript如何將如下代碼打字稿?

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

.directive('screen', function() { 
    return { 
     scope: true, 
     controller: function() { 
      this.doSomethingScreeny = function() { 
       alert("screeny!"); 
      } 
     } 
    } 
}) 

.directive('component', function() { 
    return { 
     scope: true, 
     require: '^screen', 
     controller: function($scope) { 
      this.componentFunction = function() { 
       $scope.screenCtrl.doSomethingScreeny(); 
      } 
     }, 
     link: function(scope, element, attrs, screenCtrl) { 
      scope.screenCtrl = screenCtrl 
     } 
    } 
}) 

.directive('widget', function() { 
    return { 
     scope: true, 
     require: "^component", 
     link: function(scope, element, attrs, componentCtrl) { 
      scope.widgetIt = function() { 
       componentCtrl.componentFunction(); 
      }; 
     } 
    } 
}) 


//myApp.directive('myDirective', function() {}); 
//myApp.factory('myService', function() {}); 

function MyCtrl($scope) { 
    $scope.name = 'Superhero'; 
} 

回答

0

該代碼應該照原樣工作。然而,作爲一種更好的做法,如果控制器變得太大,可以使用TypeScript類http://www.youtube.com/watch?v=WdtVn_8K17E&hd=1

+0

問題是嵌套指令如何與打字稿一起工作 – daniel

+0

「該代碼應該照原樣工作」。不是嗎? – basarat

+0

我已經在YouTube上看到過您的視頻。好工作! – daniel