0

var routerApp = angular.module('routerApp', ['ui.router','ngResource']);

routerApp.config(function($stateProvider, $urlRouterProvider) {
 
 
    $stateProvider
    // HOME STATES AND NESTED VIEWS 
      .state('partyDetail', {
         url: '/party/:partyID',
       templateUrl: 'hello.html',
        controller: function($scope, $stateParams, UserFactory) {
      
         $scope.id = $stateParams.partyID;
         console.log($stateParams.partyID);
         UserFactory.get({}, function (userFactory){
         $scope.userdata = userFactory.user;
          });
        }
       
    });
});

routerApp.controller('chappy',[function(){
 var thisOne=this;
 thisOne.note=[
  {id:1,Name:'emp.json',Status:false},
  {id:2,Name:'1',Status:true},
  {id:3, Name:'2',Status:false}
  ];
 console.log("I'm in controller");
 }]); 

routerApp.factory('UserFactory', function ($resource,$stateParams) {
console.log($stateParams.partyID);
 return $resource(':Id',{Id: $stateParams.partyID }, {
       query: {
       method: 'GET',
       params: {},
       isArray: true
        }
    })
});
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<!-- CSS (load bootstrap) -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">  

<!-- JS (load angular, ui-router, and our custom js file) -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js" ></script>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.js"></script>

<script src="app.js"></script>
</head>
<!-- apply our angular app to our site -->
<body ng-app="routerApp">
<!-- NAVIGATION -->
<nav class="navbar navbar-inverse" role="navigation" ng-controller="chappy as chappu">

<ul class="nav navbar-nav" ng-repeat="result in chappu.note">
   
  
 <li><a ui-sref="partyDetail({ partyID: result.Name })" ><span ng-bind="result.Name"></span></a></li>
</ul>
</nav>

<!-- MAIN CONTENT -->
<div class="container">
 <!-- THIS IS WHERE WE WILL INJECT OUR CONTENT ============================== -->
 <div ui-view></div>

</div>

</body>
</html>
<!--partial html which is needed to be included in the ui-view-->

<!--hello.html-->
<div>

 <p > what were you saying <span ng-bind="id"></span></p>
 <p ng-repeat="result in userdata">
  <span ng-bind="result.subject"></span>
 </p>
</div>

enter image description hereI have created Here a DemoApp in which I have dynamically Created The URi according to the data coming from the different Controller

The Programs seems to work fine at the first glance but it has a problem that the $stateparams even After changes but in the URi it remains the same

The issue here is that maybe my not services is getting called again but I am not been able to encounter this bug

var routerApp = angular.module('routerApp', ['ui.router','ngResource']);

routerApp.config(function($stateProvider, $urlRouterProvider) {


    $stateProvider
    // HOME STATES AND NESTED VIEWS 
      .state('partyDetail', {
         url: '/party/:partyID',

The Console output clearly indicates that the Uri is same as it fetch the data for the first time

Clearly, either factory is not getting called again or $stateparams is not changing

help is appreciated

  • Sorry guys I intend to convey that $stateparams is not changing in the services even after I changed the $stateparams outside the factory – harish kumar Jul 23 '15 at 11:08

1 Answers1

0

I had done some debugging of the code and I have find out since I was directly injecting the $stateparams in the factory that's why it is taking the first value it has attained to sort it out I have included the id:$stateparams in the get request in the controller and it seemed to work

controller: function($scope, $stateParams, UserFactory) {
         $scope.id = $stateParams.partyID;
         UserFactory.get({'Id': $stateParams.partyID}, function (userFactory){
         $scope.userdata = userFactory.user;
          });
          
         
        }

that's It , It will work like whammy