2017-05-13 5 views
0

私は依存関係を持つ角度ui-router次午前$ routeparamsを使用していますangular1サービスに渡されていないangular-ui-router/1.0.3/データは、私が

角度依存性の1.2.xの

angular.module('todoservice', []) 
.factory('user', ['$http','$stateParams', function($http, $stateParams){   
    userDetails: function(id){       
    //:id is working when I pass static Id which is present in mongodb 
      return $http.get('/userDetails/display/:id', id); 
//here is the problem i dont know how to pass id with angular to express(api is working perfectly)/ 
     }, 

これは私の角度コントローラである

user.userDetails(id).success(function(data){ console.log("data from services to controller", data); $scope.userDetails_test = data; });

これはドキュメントhereを参照してください、あなたはid patameterでサーバーからデータを取得しようとしているので、あなたが$http.postを使用することができ、これが私の見解である

//todo._id==> working perfectly with getting an id in the table with ng-repeat 

<a ui-sref="userDetails({id: todo._id})" ng-href = "userDetails/:todo._id" ng-click = "userDetails_scope()">userDetails</a> 
+0

あなたは '/( '$ http.getのようなURLにパラメータをCONCAT必要がありますuserDetails/display/'+ id); ' –

+0

どこに' id'を渡すのですか? 'userDetail'状態?またはデータをフェッチするサーバー側 – Pengyy

+0

サーバー側でデータを取得する場合、 – muthukumar

答えて

0

あなたは以下のようにNG-クリックに、idを渡すために試みることができる -

<a id ={id: todo._id} ui-sref="userDetails({id: todo._id})" ng-href = "userDetails/:todo._id" ng-click = "userDetails_scope(todo._id)">userDetails</a> 
+0

Idはサービスに渡されません。バックエンドサービスで渡す必要があります – muthukumar

0

私の角度の設定ファイルである

angular.module('app', ['todoController', 'todoservice','ui.router']). 
    config(['$stateProvider', function($stateProvider) { 
      $stateProvider.state('userDetails', { 
      url: '/userDetails/:id', 
       controller:'maincontroller', 
       params: {id: null,} 
     }); 
    }]); 

サンプルコード:

$http.post('/userDetails/display', {id: id}) 
    .then(function(response) {  // <------mention: here we are using then(success has been deprecated) 
     // deal with response result from server here 
    }) 
+0

これは既に内部的に行われるでしょう。 – charlietfl

+0

@pengyy私は成功サービスなしで角度1.2.xを使用しています。私は何を使うべきかわかりません。ポストメソッドで試してみました。 – muthukumar

+0

@muthukumar成功は1.2.xで使用できます。 – Pengyy

関連する問題