2013-07-18 24 views
0

我有以下幾點:如何將數據區原始狀態的狀態傳達給我的範圍?

<div data-ng-controller="AdminGridContentController" > 
     <ng-include src="'/Content/app/admin/partials/grid-content-base.html'"></ng-include> 
     <ng-include src="'/Content/app/admin/partials/table-content.html'"></ng-include> 
    </div> 

我的表包括如下所示:

<div ng-form name="page"> 
    {{ page.$pristine }} 
    <table width="100%" cellspacing="0" class="form table" > 
      <tr> 
       <th>ID</th> 
       <th>Title</th> 

      </tr> 
      <tr data-ng-repeat="row in grid.data"> 
       <td>{{ row.contentId }}</td> 
       <td><input type="text" ng-model="row.title" /></td> 
      </tr> 
    </table> 
</div> 

我想什麼做的是把那個被啓用時,在我的網基於內容的按鈕桌子上的數據變髒。我知道我可以使用{{page。$ pristine}}檢查數據的狀態,但是我怎樣才能將它傳回給grid-content-base.html?

請注意,我確實嘗試將所有內容放在「ng-form name = page」中,但是存在問題。在網格內容的基礎上,我有一個輸入選擇。只要我做一個選擇,那麼它會使頁面顯示爲髒。

因此,我仍然只是想在頁面。$ pristine變爲true或false時設置全局值。

回答

2

總是有一個選項可以做$rootScope.$broadcast並從表頁發送消息。這可以在網格頁面中處理。

像這樣的事情在表控制器

$scope.$watch('page.$pristine',function(newValue) { 
    $rootScope.broadcast("formUpdated",{state:page.$pristine}); 
}); 

而且這樣的事情在網格控制器

$scope.on("formUpdated",function(args) { 
    //args.state would have the state. 
}); 

注:$rootScope像你注入已經被注入到控制器中$scope