0

I can't understand what $scope.search is doing there, like, what it is doing when it set equals to the function? And, if i want to do in other way, how should i do?
(i am using angular js, 1.6 version)

 $scope.search = function(){
                    query.get($scope.username , {
                        success: function(gameScore) {
                            console.log(gameScore);
                            return gameScore;
                        },
                        error: function(object, error) {
                            console.log("Sorry, this user does not exist yet");
                        }
                    });
                };
Catarina Nogueira
  • 1,024
  • 2
  • 12
  • 28
  • See [Why are angular $http success/error methods deprecated? Removed from v1.6?](http://stackoverflow.com/q/35329384/5535245) – georgeawg Mar 24 '17 at 01:58
  • 1
    The $scope property named `search` is being assigned a reference to an anonymous function. See [MDN JavaScript Reference - function expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function) – georgeawg Mar 24 '17 at 02:04

2 Answers2

0

You can call $scope.search() from anywhere in your controller. You can also do something like ng-click=search() on any element in a template that is using that controller.

Calling $scope.search() will either return gameScore or print an error message to the console.

0

Not sure if this function is written in a general controller or a component controller Since you are using 1.6 Incase of it being a component controller you could attach this function to component controller and use it in your template or component

angular.module('app',[])
.component('testComponent', {
    bindings: {}.
    tempalate:'<div>$ctrl.getValue()</div>',
    controller: function(){
       var ctrl = this;
       ctrl.getValue = function() {
       console.log('log your value');
    }
  }
});