2016-01-13 46 views
0

我嘗試了一切,但我無法得到它。Angularjs獲取從控制器ng-repeat中過濾的數據

我需要的是訪問從控制器ng-repeat過濾的數據。

ng-repeat中的數據來自$ http調用。

$http.get('http://localhost:/test/test.php').success(function(data) { 

$scope.registros = data; 

}); 

,這是我試圖從我的控制器與過濾$ scope.filteredregistros正如我在其他帖子看訪問的數據視圖

<div ng-repeat="registro in (filteredregistros = (registros| filter:userSearch | filter:datefilter | filter:greaterThan('ID', greatersearch) | orderBy:'-ID'))"> 


      {{registro.ID}}{{registro.date}} 

      <div class="rowboxdata ng-animate"> 

             <div class=""><div class="name-business">{{registro.Name}}</div></div> 
             <div class=""><div class="name-business">{{registro.Phone}}</div></div> 
             <div class=""><div class="name-business">{{registro.Email}}</div></div> 
             <div class=""><div class="name-business">{{registro.Name}}</div></div> 
             <div class=""><div class="name-business">{{registro.City}}</div></div> 
             <div class=""><div class="name-business">{{registro.Service}}</div></div> 
      </div> 

</div> 

,但它沒有工作給我。

我想要做的是獲取數據過濾,然後通過ajax發送給php。

會不錯,謝謝。

EDITED

最後,我已經找到了我需要用這個例子;

在查看:

<input type="button" ng-click="results(filteredregistros)" /> 

在控制器:

$scope.results = function (filteredregistros) { 
      console.log(filteredregistros); 
      // your ajax code 
}; 

如果你想要得到它只是在視圖中,然後執行它作爲每Hornshøj-Schierbeck說:

filteredregistros: {{filteredregistros | json}} 

感謝您的幫助PerHornshøj-Schierbeck

+0

你能給我提供樣品json嗎? –

+0

顯示您嘗試讀取過濾後的寄存器的示例。請記住,數據將無法訪問,直到您的http請求完成並且過濾器代碼運行... –

+0

@PerHornshøj-Schierbeck以及所有我嘗試過的是var test1 = $ scope.filteredregistros; console.log(test1) – nanaki

回答

1

嘗試在你的HTML添加

filteredregistros: {{filteredregistros | json}} 

地方。應該清楚它是否包含數據。通過json管道將以json格式顯示數據,這對於調試裏面的值很不錯。

當你做console.log的時候,你可能不會看到,你的http請求可能運行也可能沒有運行,而且數據可能還沒有被過濾,具體取決於你何時console.log

+0

那麼您的registros值是什麼?你可以在HTML中調試它們,或者直接在console.log中記錄你的成功方法中的數據在$ http.get調用 –

+0

我忘了在我的php mysql_fetch_array中更改爲mysql_fetch_object這就是爲什麼它返回數字和屬性而不是屬性 – nanaki

+0

因此,它解決了你的問題或現在有什麼問題? –

相關問題