javascript
  • angularjs
  • 2014-01-19 191 views 0 likes 
    0

    我有這樣的HTML結構控制器範圍內跨範圍

    <div kendo-splitter k-orientation="'horizontal'" k-panes='[{ collapsible: true, size: "15%" } 
                    , { collapsible: false } 
                    , { collapsible: true, size: "15%" }]' style="position: absolute; top: 5%; left: 0%; height: 80%; width: 100%"> 
          <div>Incident</div> 
          <div ng-controller="layoutController"> 
           Video 
           <nv-layout id="nv-layout" layout-entries="layoutEntries" on-selected="onSlotSelected" on-resize="onLayoutResized"></nv-layout> 
          </div> 
          <div>Sensors</div> 
         </div> 
    

    NV-佈局指令被定義爲

    var directive = { 
         link: link, 
         restrict: 'EA', 
         scope: { 
          layoutEntries: "=", 
          selected: "&onSelected", 
          resized: "&onResized" 
         }, 
         template: "<div></div>" 
        }; 
    

    我希望把控制器分離器DIV所以這將是能聽調整大小的事件,如何當我做到了layoutEntries綁定打破,是否有限制,我可以添加控制器?

    回答

    0

    當您堅持自定義指令時,角度最容易。如果你想我可以提供一個例子。

    要回答你的問題「我可以在哪裏添加控制器有限制嗎?」

    是的,它必須高於您希望控制的代碼。在您的示例中,您的控制器上方和下方都有Angular代碼。但是,您可以嵌套控制器。喜歡的東西...

    <div ng-controller="MainCtrl"> 
        <div kendo-splitter k-orientation="'horizontal'" k-panes='[{ collapsible: true, size: "15%" } 
                   , { collapsible: false } 
                   , { collapsible: true, size: "15%" }]' style="position: absolute; top: 5%; left: 0%; height: 80%; width: 100%"> 
         <div>Incident</div> 
         <div ng-controller="layoutController"> 
          Video 
          <nv-layout id="nv-layout" layout-entries="layoutEntries" on-selected="onSlotSelected" on-resize="onLayoutResized"></nv-layout> 
         </div> 
         <div>Sensors</div> 
        </div> 
    </div> 
    

    然後在你的js文件

    app.controller('MainCtrl',function($scope){ 
        $scope.blah = 'blah' 
    }); 
    
    app.controller('layoutController',function($scope){ 
        $scope.blah = 'blah' 
    }); 
    

    另外,你可能要遵循Angularjs風格指南和UppderCamelCase標記您的控制器。

    這裏是一個鏈接:

    A Style Guide

    相關問題