0

I am trying to pass data from $scope.abc() to an actual function.

[Function]

function sweetAlertCtrl($scope, SweetAlert, $state) {
    $scope.demo1 = function () {
        SweetAlert.swal({
            title: "Good job!",
            text: "You clicked the button!",
            type: "success"
        },
        function ($state) {
            $state.go('pjt.detailed', {id: $scope.id}) // This is where the data from $scope is received.
        });
    }
}

[Data from $scope]

$scope.demo1($scope.id);

How can I pass $scope.id to demo1() function? Did I even put the $state in the correct location? I am new to this and this is really confusing :)

Please advise me what I should do.

Thank you so much in advance!!

2 Answers 2

2

Put $state among the other dependencies in your controller/service/factory/etc, like this:

app.service('myService', function($scope, $state) {
    // Now you can use $state in all your functions here
})
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your comment! Yes, you are right. I was missing that part. It was easy to make an action, but hard to find what the problem was. :) Thank you so much!
Providing a bit more code as answer is sometimes helpful ;)
1

Pass in the $scope.id as a parameter to the function $scope.demo1:

$scope.demo1 = function (id) {
    SweetAlert.swal({
        title: "Good job!",
        text: "You clicked the button!",
        type: "success"
    },
    function ($state) {
        $state.go('pjt.detailed', {id: id})
    });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.