私はこのコントローラーを持っています:
app.controller('BuscadorClientesController', function(){
this.clientes = [
{
tipo: {
nombre: "Sarasa"
},
nombre: "Alan",
direccion: "Fake Address 1234",
telefono: "12341234",
email: "ipsum@gmail.com",
rubro: "Lorem",
id: "1"
}
]
});
私の見解では、「clientes」配列は正常に印刷されていますが、データベースからクライアントを取得したいので、これを作成しました
app.service('Clientes', function ($http) {
this.getAll = function (success, failure) {
$http.get('/api/clientes')
.success(success)
.error(failure);
}
});
app.controller('BuscadorClientesController', function($scope, Clientes){
Clientes.getAll(function(data){
$scope.clientes = data
console.log($scope.clientes)
});
});
console.log($scope.clientes) は正しいデータ (多くのオブジェクトを含む配列) を出力していますが、私のビューには表示されません:
<tr ng-repeat="cliente in buscador.clientes">
<td><%= cliente.tipo.nombre %></td>
<td><%= cliente.nombre %></td>
<td><%= cliente.direccion %></td>
<td><%= cliente.telefono %></td>
<td><%= cliente.email %></td>
<td><%= cliente.rubro %></td>
</tr>
私は何を間違っていますか?
編集:
コントローラーのコードを次のように変更しました。
app.controller('BuscadorClientesController', function(Clientes){
var that = this
Clientes.getAll(function(data){
that.clientes = data
console.log($scope.clientes)
});
});
それは正しい方法ですか、それとももっと良い方法はありますか?