2016-11-24 1 views
0

これは、main.htmlと構造NG-ルートが機能していますが、JSONからidのidが間違っている

<ul ng-repeat = 'user in users'>  
<li>{{user.first_name}} <span>X</span></li> 
<li>{{user.last_name}}</li> 
<li>{{user.email}}</li> 
<a href="#footer/{{user.id}}"/><li>{{user.id}}</li></a> 
</ul> 

ですこれは

app.config(function($routeProvider) { 
$routeProvider 
.when("/footer/:id",{ 
templateUrl:'./footer.html', 
controller: "getCtrl" 
}) 
.when("/nemke",{ 
templateUrl:"./form.html" 
}) 
.otherwise({ 
redirectTo:"/" 
}) 
}); 
app.controller('secondCtrl', function($scope) { 
$scope.name = "nemkesafsafa"; 

}); 

これは、main.jsファイルは私のroute.jsです

var app = angular.module("app",['ngRoute']); 
app.controller('getCtrl',['$scope', '$http', '$routeParams', 'users', function($scope, $http, $routeParams, users) { 
users.success(function(data){ 
var obje = data[0].first_name; 
console.log(obje); 
var keys = []; 
$scope.profile = data[$routeParams.id]; 

for(var i = 0; i< data.length; i++) { 
    keys.push(data[i].id); 
} 
$scope.users = data; 
}); 
users.error(function(){ 
    console.log("Nemke") 
}) 
}]); 

json.php

[{"id":"126","first_name":"Nemanja","last_name":"Dukic","email":"Car"},{"id":"127","first_name":"Nemanja","last_name":"Dukic","email":"Car"}] 

私がリンクをclikcときfooter.html

<div> 
<h2>{{profile.id}}</h2> 
<h2>{{profile.fist_name}}</h2> 
<h2>{{profile.last_name}}</h2> 
<h2>{{profile.email}}</h2> 

</div> 

だから問題はURLが細かいですが、データdipslay識別footer.htmlは間違っている

ここではeasireこのよう

だpicuterです

下の画像の説明を参照してください。事前に

enter image description here

感謝。

+0

を交換する必要がありますあなたのfooter.htmlはさらに$ scope.profile =データのように見えている何[$ routeParams.id]。あなたはidにフィルタリングされるべきではないインデックスに基づいた要素を譲渡していますか? –

+0

where is footer.html –

+0

申し訳ありません更新されたフッターの答え@VinodLouis – NemanjaD

答えて

1

$ scope.profile = data [$ routeParams.id];

$scope.profile = data.find(function(ele){ 
    return ele.id == $routeParams.id 
}); 
+0

ありがとう、これは素晴らしい作品です。 – NemanjaD

関連する問題