当前位置: 动力学知识库 > 问答 > 编程问答 >

angularjs - Pass Value as parameter from ngDialog to another controller

问题描述:

Below is my code snippet

$scope.openrights = function (userid) {

$scope.valid = userid;

ngDialog.open({

template: 'views/rightsassignment.html',

controller: 'RightsCtrl',

className: 'ngdialog-theme-default ngdialog-theme-custom',

scope: $scope

});

};

Problem I am having is --- I could not pass the 'valid' scoped value to controller RightsCtrl.

scope: $scope passes the value only to html template mentioned as intepolated value {{valid}}.

How to pass the value 'valid' as parameter to RightsCtrl as $state.params.valid ?

Any Help would be appreciated

I have a state in app.js as

 .state('companyadmin.rightsassignment', {

url: '/rightsassignment/:valid',

templateUrl: 'views/rightsassignment.html',

controller: 'RightsCtrl',

title: 'Welcome Company Admin'

})

网友答案:

Pass the parameter as query param to that state or maintain a variable in rootScope.

$rootScope.isValid = false;

Change this value isValid in your ngDialog controller accordingly.

As $rootScope is available in all the controllers, you should be able to use it.

Edit: I see that you have a path param :valid in your state. You should be passing your valid valid to that state when you are transitioning from modal to state.

$state.go("companyadmin.rightsassignment", { "valid": true }
网友答案:

Check This - you need to pass variables with data property

$scope.valid = userid;
ngDialog.open({ template: 'templateId',
className: 'ngdialog-theme-default ngdialog-theme-custom',
data: $scope.valid,
controller: ['$scope', function($scope) {

        // controller logic

                alert($scope.valid);


    }]
    });
分享给朋友:
您可能感兴趣的文章:
随机阅读: