Dynamically set the value of ui-sref Angularjs

前端 未结 12 1815
囚心锁ツ
囚心锁ツ 2020-11-28 04:15

I have searched for a similar question but the ones that came up seem slightly different. I am trying to change the ui-sref=\'\' of a link dynamically (this link points to t

12条回答
  •  野性不改
    2020-11-28 05:01

    The best approach is to make use of uiRouter's $state.go('stateName', {params}) on button's ng-click directive. And disable the button if no option is selected.

    HTML

    
    
    

    Controller

    function Controller($scope, $state){
        this.options = [{
            text: 'Option One',
            state: 'app.one',
            params: {
                param1: 'a',
                param2: 'b'
            }
        },{
            text: 'Option Two',
            state: 'app.two',
            params: {
                param1: 'c',
                param2: 'd'
            }
        },{
            text: 'Option Three',
            state: 'app.three',
            params: {
                param1: 'e',
                param2: 'f'
            }
        }];
    
        this.next = function(){
            if(scope.selected){
                $state.go($scope.selected.state, $scope.selected.params || {});
            }
        };
    }
    

    State

    $stateProvider.state('wizard', {
        url: '/wizard/:param1/:param2', // or '/wizard?param1¶m2'
        templateUrl: 'wizard.html',
        controller: 'Controller as ctrl'
    });
    

提交回复
热议问题