0

I have a button that loads the a view using ui router

<button ui-sref="manageactivity.update" >Edit Event</button>

and I would like to pass a {{activity.id}} into the template

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

$stateProvider          
    .state('manageactivity.update', {
        url: '/update/:id',
        templateUrl: "update.html",
        controller: 'eventMgmtCtrl'     
    }); 
});

app.controller("eventMgmtCtrl", function ($scope,$stateParams) {
    $scope.testID = $stateParams.id;    
});

I do know how to do it in normal angular routing, by passing it through the url as such, but it does not work for ui router because ui-router uses the name of the state instead of the url?

<button data-ng-href="#Update/{{activity.id}}" >Edit Event</button>

What changes do I need ?

2 Answers 2

4

You can pass data in ui-sref as

<button ui-sref="manageactivity.update({id: activity.id})" >Edit Event</button>

And you can access it in the page using the $stateParams as you defined in the question...Good Luck

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

Comments

3

You can pass data in "ui-sref" as following way:

HTML:-

<button ui-sref="manageactivity.update({'id':'activity.id'})" >Edit Event</button>

Than you can receive data in controller as following way:-

Controller:-

 $scope.id = $stateParams.id;

Comments

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.