Im using https://github.com/mgonto/angular-wizard to create an angular wizard whose steps can be called from route params:
- .../step/1
- .../step/2
etc.
So I've created this controller:
.controller('createOrganizer', ['$scope', 'WizardHandler' , '$routeParams',
function($scope,WizardHandler,$routeParams)
{
//$scope.data = {};
$step = $routeParams.step;
WizardHandler.wizard().goTo($step);
}])
The proper linking and routing were created correctly on app.js and the index.html
But when I get into the urls, I get this:
TypeError: Cannot call method 'goTo' of undefined
Is this the way to pre-select an angular-wizard step using url parameters?
================= Update =====================
I tried with something like this:
.controller('createOrganizer', ['$scope', 'WizardHandler' , '$routeParams', function($scope,WizardHandler,$routeParams) { $step = $routeParams.step;
$scope.$watch(WizardHandler.wizard(), function(step) {
WizardHandler.wizard().goTo($step);
});
}])
The idea is to ise watch to tell me when WizardHandler.wizard() is instantiated in order to call the .goTo method. With this controller im getting this error:
TypeError: Cannot set property 'selected' of undefined
Not sure if i am using watch correctly. I even tested the step variable and it is ok, showing the same value as the url.
================= Solved! =====================
var step = parseInt($routeParams.step); // Important, as routeParams returns an String: the wizardHandler uses either an integer number or a string name of step. So I am parsing the number to prevent confusion.
$scope.$watch(
function() {return WizardHandler.wizard();},
function (wizard) {
if (wizard) wizard.goTo(step);
});
I added an init(step) function that handles the initial values of some values i need and also prevents error caused by urls like .../step/SOMERANDOMSTRING
Thanks to GregL for your help!