D
D
DadFild2015-07-30 23:43:07
JavaScript
DadFild, 2015-07-30 23:43:07

How to run a function directly in Angular?

<button class="btn btn-md btn-md-primary" ng-click="importContact()" my-i18n="contacts_modal_new_contact">New contact</button>


What js needs to be executed to run importContact()

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2015-07-31
Protko @Fesor

add a scoped function to the module's run or, better yet, write a controller.

I
Ilya Agarkov, 2015-07-31
@ElianL

I don’t know what task you are trying to solve, but if you need a function to be called when a button appears in the DOM, then you can use ng-init

<button class="btn btn-md btn-md-primary" ng-init="importContact()" ng-click="importContact()" my-i18n="contacts_modal_new_contact">New contact</button>

A
Alex, 2015-07-31
@streetflush

I understand that we are talking about the good old clickers on the sites. Right?
And if everything is simple with JS, then pulling a function from $scope is problematic.
If from the console, then there is an extension to Batarang chrome.
I pull like this

angular.element($0).scope().addTodo(); // Дергаю функцию
angular.element($0).scope().$apply(); // Для обновления данных на экране

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question