angularjs-service

Passing asynchronously obtained data to a directive

拜拜、爱过 提交于 2019-11-29 07:46:01
I currently have an AngularJS controller that is basically getting some JSON asynchronously through a $http.get() call, then linking the obtained data to some scope variable. A resumed version of the controller code: mapsControllers.controller('interactionsController', ['$http', function($http) { var ctrlModel = this; $http.get("data/interactionsPages.json"). success(function(data) { ctrlModel.sidebar = {}; ctrlModel.sidebar.pages = data; }). error(function() {...}); }]); Then, I have a custom directive which receives those same scope variables through a HTML element. A resumed version of the

Simple Angular $routeProvider resolve test. What is wrong with this code?

╄→гoц情女王★ 提交于 2019-11-29 07:37:25
I have created a simple Angular JS $routeProvider resolve test application. It gives the following error: Error: Unknown provider: dataProvider <- data I would appreciate it if someone could identify where I have gone wrong. index.html <!DOCTYPE html> <html ng-app="ResolveTest"> <head> <title>Resolve Test</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.js"> </script> <script src="ResolveTest.js"></script> </head> <body ng-controller="ResolveCtrl"> <div ng-view></div> </body> </html> ResolveTest.js var rt = angular.module("ResolveTest",[]); rt.config(["

Angular - TypeError: XX is not a function

走远了吗. 提交于 2019-11-29 02:00:00
Maybe I'm missing some kind of property, but I'm follow this project and I'm getting this error in my controller. TypeError: loginService.signin is not a function This is my controller.js angular.module('appcontrollers', []).controller('LoginController', ['$rootScope', '$scope', '$http', '$location', '$localStorage', 'loginService', function ($rootScope, $scope, $http, loginService) { $scope.signin = function() { console.log("username: " + $scope.username); console.log("pass: " + $scope.password); var formData = { username: $scope.username, password: $scope.password }; // ERROR IN THIS LINE

Stop request in angularjs interceptor

三世轮回 提交于 2019-11-28 23:17:39
How can I stop a request in Angularjs interceptor. Is there any way to do that? I tried using promises and sending reject instead of resolve ! .factory('connectionInterceptor', ['$q', '$timeout', function($q, $timeout) { var connectionInterceptor = { request: function(config) { var q = $q.defer(); $timeout(function() { q.reject(); }, 2000) return q.promise; // return config; } } return connectionInterceptor; } ]) .config(function($httpProvider) { $httpProvider.interceptors.push('connectionInterceptor'); }); The $http service has an options timeout to do the job. you can do like: angular.module

AngularJS service retry when promise is rejected

一个人想着一个人 提交于 2019-11-28 17:58:49
I'm getting data from an async service inside my controller like this: myApp.controller('myController', ['$scope', 'AsyncService', function($scope, AsyncService) { $scope.getData = function(query) { return AsyncService.query(query).then(function(response) { // Got success response, return promise return response; }, function(reason) { // Got error, query again in one second // ??? }); } }]); My questions: How to query the service again when I get error from service without returning the promise. Would it be better to do this in my service? Thanks! You can retry the request in the service

AngularJS Error: $injector:unpr Unknown Provider

半世苍凉 提交于 2019-11-28 17:44:19
I'm trying to build my own service by following the example in the documentation for the factory methodology. I think I've done something wrong however because I continue to get the unknown provider error. This is my code for my app including the declaration, configuration and factory definition. EDIT I've now added all of the files to help troubleshoot EDIT The full details of the error are below the issues appears to be with getSettings, as it's looking for getSettingsProvider and cannot find it Error: [$injector:unpr] http://errors.angularjs.org/1.2.16/$injector/unpr? p0=getSettingsProvider

$watch inside a service?

岁酱吖の 提交于 2019-11-28 16:57:12
Is it possible to set up a $watch on an array of objects inside a service (I'd like the $watch declaration itself to be inside the service)? You can add any expression to the set of watches by injecting the $rootScope and using a function a first argument to the $watch method. Pseudo-code: $rootScope.$watch(function() { return //value to be watched; }, function watchCallback(newValue, oldValue) { //react on value change here }); Don't forget about the third, Boolean argument to the $watch method. You need to specify true if you want to deep-watch an entire object for changes. services by their

AngularJS, is this way of using service good?

扶醉桌前 提交于 2019-11-28 16:52:16
i've this HTML: <p>Hello {{name}}</p> and the controller is: function myCtrl(scope, service) { scope.name = service.getUsername(); // service.getUsername() return "World!" } myCtrl.$inject = ['$scope', 'originalService']; The service works fine, so i don't paste the code here... In this case the result is " Hello world! " I changed the HTML in this way: <p>Hello {{service.getUsername()}}</p> But this does not work. I changed the controller: function myCtrl(scope, service) { scope.ser = service; } myCtrl.$inject = ['$scope', 'originalService']; and then the HTML <p>Hello {{ser.getUsername();}}<

How can I define an AngularJS service using a TypeScript class that doesn't pollute the global scope?

前提是你 提交于 2019-11-28 16:41:34
I am using AngularJS and TypeScript. I want to implement an AngularJS service using a Typescript class, like this: class HelloService { public getWelcomeMessage():String { return "Hello"; } } angular.module('app.services.helloService', []).factory('helloService', () => { return new HelloService(); }); This compiles to the following javascript code: var HelloService = (function () { function HelloService() { } HelloService.prototype.getWelcomeMessage = function () { return "Hello"; }; return HelloService; })(); angular.module('app.services.helloService', []).factory('helloService', function ()

Restangular api calls to external getting 'No Access Allowed'

泄露秘密 提交于 2019-11-28 11:31:29
问题 Following Restangular's documentation and includes an example of this: // GET to http://www.google.com/ You set the URL in this case Restangular.allUrl('googlers', 'http://www.google.com/').getList(); I am trying to do the same for angel.co $scope.trial = Restangular.allUrl('googlers', 'https://api.angel.co/1/users/267770').getList(); And keep getting error XMLHttpRequest cannot load https://api.angel.co/1/users/267770. No 'Access-Control-Allow-Origin' header is present on the requested