0

I am a novice.I have a line of code like this that was written for me.

<a class="pull-right btn btn-primary" ng-click="addWidget()"><i class="glyphicon glyphicon-plus"></i> Add Widget</a>

Which works perfectly (it adds the widget which is a box element to the page). The function is defined in the controller DashboarCtrl like this

    $scope.addWidget = function() {
        $scope.dashboard.widgets.push({
            name: "New Widget",
            sizeX: 1,
            sizeY: 1
        });
    };

How do invoke that same function in the console? I have tried angular.element('#DashboardCtrl').scope().addWidget();

1 Answer 1

2

Lets just say that your add Widget link has an id (add_widget). Then you can find the element by id and click it.

<a id="add_widget" class="pull-right btn btn-primary" ng-click="addWidget()">
    <i class="glyphicon glyphicon-plus"></i> Add Widget
</a>

angular.element('#add_widget').click();

Sign up to request clarification or add additional context in comments.

1 Comment

So simple when one knows. Thank you, that is it.

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.