Nasuh Nasuh - 2 months ago 10
AngularJS Question

Dont show the $stateParams value in the link

I want to access the

$stateParams
value on my controller but I dont want to show the value on the links. Is this possible?

HTML

<a ui-sref="baba.watch({name: card.name, aktar: {chapter:card.chapter, link:card.link}})">


Javascript

.state('baba.series', {
url: "/series/:name/:aktar",
templateUrl: "states/baba.series.html",
controller: "nbgCtrl"
});

.controller('nbgCtrl', function ($scope, $stateParams) {
$scope.milo = $stateParams.aktar.link;
console.log($scope.milo);


I am getting undefined.
Links should be look like
/series/Naruto/345
. Show the chapter value do not show the link value.

Edit: Output of $stateParams:

isim:"Naruto",
aktar:"[object Object]"

Answer

You can set data on the state, it will not be displayed on the URL when the state loads.

.state('baba.series', {
  url: "/series",
  templateUrl: "states/baba.series.html",
  controller: "nbgCtrl",
  data: {
    link: 'some value',
    isim: 'Value', 
    aktar: 'Value'
  }
});

You can now retrieve the values from your controller

.controller('nbgCtrl', function ($scope, $state) {
  $scope.milo = $state.data.link;
  $scope.isim = $state.data.isim;
  $scope.aktar = $state.data.aktar;
  console.log($scope.milo);
}
Comments