0

Im Passing Selected Car Id in Url and trying to get data in console.log don't know where i'm missing may be i'm confused checking too much solution in stackoverflow - here is my code :

//Controller.js

     $scope.chooseACar = function(selectCarId)
            { 
               $scope.selectCarId = $stateParams.selectCarId;
                console.log($scope.selectCarId);
            }

//App.js

    .state('main.step3', 
    {
        url: '/step2/:selectCarId',
        templateUrl: 'pages/step3.html'
    });

//services.js

get: function(selectCarId) {
    for (var i = 0; i < carListData.length; i++) {
      if (carListData[i].id === parseInt(selectCarId)) {
        console.log(carListData[i]);
        return carListData[i];
      }
    }
    return null;
  }

// HTML Code

<a type="submit" href="#/main/step2/{{selectCarList.id}}" class="button button-yellow button-full submitBtn" style="color:#000; display:block">CHOOSE A CAR</a>

2 Answers 2

2

In App.js (if you are getting ID in url no need to modify.)

.state('main.step2', {
    name: 'slectcarID'
    url: '/step2/:selectCarId',
    templateUrl: 'pages/step3.html'
});

and to get the data in controller use $stateParams

console.log($stateParams.selectCarId);

or

$scope.selectCarId = $stateParams.selectCarId;
console.log($scope.selectCarId);

Try either only ng-click or ui-sref

Sign up to request clarification or add additional context in comments.

9 Comments

Getting Undefined Value!!
Is the ID getting appended in URL ?
Hey try removing ng-href="#/main/step2/{{selectCarList.id}}" in your HTML. and check if selectCar value is getting pased in chooseAcar function.
I removed ng-href. Now button is not working !! its not getting clicked
Are you sure you want it <a> tag ? Please change a to div tag or just remove ng-click from the html and try
|
0

Try using ui-sref instead of href

HTML

<a type="submit" ui-sref="main.step3({carId : selectCarList.id})"
   class="button button-yellow button-full submitBtn" 
   style="color:#000; display:block">CHOOSE A CAR
</a>

App.js

.state('main.step3', 
{
    url: '/step2/:selectCarId',
    templateUrl: 'pages/step3.html',
    controller: `Your Controller Name`,
    params: { carId: null, }
});

Controller

$scope.chooseACar = function(){ 
                                  $scope.selectCarId = $stateParams.carId;
                                  console.log($scope.selectCarId);
                              }

6 Comments

Do i need to define controller again. i mean i already define main controller and I don't want to define it again.
No need, in your controller it self.
so you define controller here do i put my controller name .state('main.step3', { url: '/step2/:selectCarId', templateUrl: 'pages/step3.html', controller: ctrl, params: { carId: null, } });
in app.js along with url,templateUrl include controller and params
here controller means, the name of the controller from which view is rendering
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.