I'm working on passing parameters in a url. As far as I know everything is setup correct to set the baseFilter url parameter with the vm.all property but every time I click the link nothing happens. I also inspected the generated html and I see a ui-sref and not a href tag. Any help is appreciated
router.js
(function () {
'use strict';
angular.module('app').config(routing);
/* @ngInject */
function routing($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'home/home.html',
controller: 'HomeContentController as vm'
})
.state('eventsList', {
url: '/eventsList/:baseFilter',
templateUrl: 'events-list/events-list.html',
controller: 'EventsListController as vm'
});
$urlRouterProvider.otherwise('/home');
}
})();
This is the a tag in my home.html
<a class="item" ui-sref="eventsList({baseFilter: vm.all})">
HomeController.js
(function () {
'use strict';
angular.module('app').controller('HomeContentController', HomeContentController);
/* @ngInject */
function HomeContentController($scope, $log, $ionicSideMenuDelegate, $ionicPopup, $state, rxEventsService, rxRequests, $cordovaGeolocation) {
// Assign variable `vm` to `this` to reflect that this is a view-model.
var vm = this;
vm.all = "all";
// Bindable Properties
vm.promptUnavailable = promptUnavailable;
// Controller Initialization
function init() {
console.log('init HomeContentController');
}
init();
// Bindable Events
function promptUnavailable(feature) {
$ionicPopup.alert({
title: 'Unavailable Feature',
template: feature + ' is unavailable in this Alpha release'
});
}
}
})();
If you set the correct value of vm.all
your code should work fine.
angular
.module('app', ['ui.router'])
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'home.html',
controller: 'HomeContentController as vm'
})
.state('eventsList', {
url: '/eventsList/:baseFilter',
templateUrl: 'events-list.html',
controller: 'EventsListController as vm'
});
$urlRouterProvider.otherwise('/home');
})
.controller('HomeContentController', function () {
var vm = this;
vm.all = 1;
})
.controller('EventsListController', function ($stateParams) {
var vm = this;
console.log($stateParams);
});
I have created a JSBin using your code and it works fine. If you see the value logged in console log, it has correct value of $stateParams
. https://jsbin.com/qebimeh/1/edit?html,js,console,output