-1

I have a controller where i am fetching subrolename of user i want to use this subrolename in my view to give conditions and my view is in angularjs how can i fetch that subrolename in my view

Gilad Green
  • 36,708
  • 7
  • 61
  • 95
  • make an http call from your angular controller (via an angular data service) and have this in your angular controller's scope and use that. What specific problem are you having in the approach you tried ? Can you share some code you tried – Shyju Jul 08 '16 at 14:10

2 Answers2

1
  1. In your controller assign it to the $scope: $scope.subrolename = mySubrolename;
  2. In your view do: {{subrolename}}.

See AngularJS's documentation (second example)

If you show some of your code we can show a more specific example

Gilad Green
  • 36,708
  • 7
  • 61
  • 95
1

Another way of doing it outer or @Gilad Green way is using this.

Your Controller:

myApp.controller('MyController', function(){

  // First Way
  this.subrolename = mySubreolename;

  // Second Way
  var vm = this;
  vm.subrolename = mySubreolename;

});

And in your View:

{{myController.subrolename}} 

That's very useful when you want to specify which controller you want to use and making sure no other controllers are trying to handle a specific variable.

Hope I've been helpful.

Community
  • 1
  • 1
AndreaM16
  • 3,917
  • 4
  • 35
  • 74