0

I am facing one issue while setting the a tag value dynamically using Angular.ja ui-router. I am providing my code below.

<a ui-sref="{{mastUrl}}" ng-show="isMaster">Master Info</a>
$scope.mastUrl='app.ownerinfo.owner.vew';
var url='../service/admin/login/checkmenu.php';
    var method='GET';
    var data='';
    DataService.connectToServerSideScript(method,url,data)
    .then(function(response) {
        console.log('menu',response);
        if (response.length > 0) {
            angular.forEach(response,function(obj){
                if (obj.user_type==2) {
                    $scope.isUser=false;

                    if (obj.isMast==0) {
                        $scope.isMaster=false;
                    }else{
                        $scope.isMaster=true;
                        if (obj.mastUrl !='') {
                            $scope.mastUrl=obj.mastUrl;
                        }
                    }
                }
            })
        }
    },function(error) {

    })

Here I have default value of app.ownerinfo.owner.vew for $scope.mastUrl but inside the service I need to set it dynamically. As per my current example it value is app.ownerinfo.owner.new inside the service success response. But the generated output HTML of a tag is coming like below.

<a ui-sref="app.ownerinfo.owner.new" ng-show="isMaster"
   href="#!/ownerinfo/owner/view">Master Info</a>

My routing code is given below.

.state('app.ownerinfo',{
        url:'/ownerinfo',
        templateUrl:'view/ownerinfo.html',
        controller:'ownerinfoController'
    })
    .state('app.ownerinfo.owner',{
        url:'/owner',
        templateUrl:'view/owner.html',
        controller:'ownerController'
    })
    .state('app.ownerinfo.owner.vew',{
        url:'/view',
        templateUrl:'view/ownerview.html',
        controller:'ownerviewController'
    })
    .state('app.ownerinfo.owner.new',{
        url:'/new',
        templateUrl:'view/newowner.html',
        controller:'newownerController'
    })

Here ui-serf value is set as expected but href value is same as default value. I need to set both value same.

halfer
  • 19,824
  • 17
  • 99
  • 186
satya
  • 3,508
  • 11
  • 50
  • 130

2 Answers2

0

I think a better way is to use the ng-click tag to a controller method and in that method use the $window.location.href = 'URL'; syntax to redirect the user. That way, your redirect (url building) stays in the controller logic.

Verthosa
  • 1,671
  • 1
  • 15
  • 37
  • Yes..It can solve using your way but here I have the requirement as per menu privilege those will display to user. – satya Jun 13 '19 at 07:02
0

You can use ui-state directive, which allows dynamic links:

<a data-ui-state="selectedState.state" data-ui-state-params="{'myParam':aMyParam}">
       Link to page {{selectedState.name}} with myParam = {{aMyParam}}
  </a>

Here is github discussion about the same problem: github

And here the 3rd answer that helps you: answer

Bill P
  • 3,622
  • 10
  • 20
  • 32