0

Is there a way to call an outside javascript function inside angularJS brackets, without having to use signals?

For example:

HTML

<td data-title="'PHONE'"> {{ formatPhone(p.phone) }} </td>

JAVASCRIPT

var app = angular.module('myapp', [ 'ngTable' ]);

//my controller
app.controller('MyController', function($scope, $http, NgTableParams) {

    //...

});

//my outside function
var formatPhone = function(p) {
    //...
};
3
  • You can't evaluate unless the function is attached to some scope Commented Feb 21, 2018 at 12:46
  • Why do you even want to do that ? What would that make any difference from attaching scope tot the function? Commented Feb 21, 2018 at 13:15
  • @Angular_10 to reuse code and avoid having equal functions on my code. But I solve that by calling this function from another function attached on the scope. Commented Feb 21, 2018 at 13:51

1 Answer 1

2

In order to use a scope function, it needs to exists in the scope. You can just pass the function inside of the controller.

app.controller('MyController', function($scope, $http, NgTableParams) {
     $scope.formatPhone = formatPhone
});

//my outside function
var formatPhone = function(p) {
    //...
};
Sign up to request clarification or add additional context in comments.

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.