angularjs - Javascript outside angular js -
in angular js instead of using service in module, can create javascript functions outside controller , call when want to?
for example:
var urlpath="http://www.w3schools.com//angular//customers.php" //this contain functions function testing_model ($http){ var self=this; self.getrecords=function(){ $http({ method:'get', url: urlpath, }).success(function(data){ self.record=data.records; }); } self.getrecords(); } angular.module("myapp", []); app.controller('mycontroller', function ($scope, $http) { $scope.testing_model = new testing_model();} when run code above, says "$http not function".
thanks in advance.
you need pass $http function...
$scope.testing_model = new testing_model($http); although work goes against idea of angular. must inject function service in controller write testable code, track dependencies , respect other developers going support project later.
Comments
Post a Comment