2016-05-08 10 views
1

AngularjsとNodejsを初めて使用しています。 AngularJsを使用してボタンをクリックした後、card.htmlページを呼び出そうとしています。また、card.htmlページには、コントローラから取得した「scope.resultCards」が表示されます。どのように私は同じを達成する必要がありますか?どんな助けや助言も高く評価されます。ありがとうございました !angularJsとNodejsを使用して別のhtmlページにリダイレクト

私のhtmlページは次のようになります。

  <div id ="button_spaces"> 
      <table> 
       <tbody> 
        <tr ng-repeat="result in results"> 
        <br> 
        <form action="/card"> 
         <td> <input type ="submit" ng-click="getcards(result.setIdNum)" value = {{result.Category}} > 
         </td> 
        </form> 
        </tr> 
       </tbody> 
      </table> 
     </form> 
    </div> 
</div> 

次のように私のクライアントコントローラは、次のとおりです。 $ scope.getcards =機能(setIdNum){

 var url = "/cards/"+setIdNum; 
     console.log(" cards url "+ url); 

      $http.get(url).success(function(data){ 
      $scope.resultCards = data; 

      console.log("Test cards: ", $scope.resultCards); 
     }); 
    } 

と私のserver.jsコードはfoですllows: app.get( '/カード/:setIdNum'、関数(REQ、RES){

var searchrequest = req.params.setIdNum; 
Cards.find({settIdNum: searchrequest},function(err, found) { 

     if (err) 
      res.send(err) 
     else 
     res.json(found); // return all cards in JSON format 

    }); 
}); 
+0

こんにちはDipali、クリック後にページをリダイレクトする必要がありましたか? –

+0

こんにちはSiva。はいボタンをクリックした後、私は($ scope.resultCards)の内容を表示する別のページ(card.html)にリダイレクトする必要があります – Dipali

答えて

0

使用$state.goUI Router

$scope.getcards = function(setIdNum) { 
     var url = "/cards/"+setIdNum; 
     console.log(" cards url "+ url); 

     $http.get(url).success(function(data){ 
      $scope.resultCards = data; 
      console.log("Test cards: ", $scope.resultCards); 
      $state.go("card", { cards: $scope.resultCards }); 
     }); 
    } 
の公式文書を参照してください、PARAMと別のビューにリダイレクトします
+0

あなたの助けを借りてシヴァに感謝します。私は実際に$ location.path(url)を使って解決しました。 – Dipali

+0

ありがとうDipali :) –

関連する問題