angularjs-service

AngularJS Service not working

孤街浪徒 提交于 2019-12-12 19:11:40
问题 I have been developing a simple AngularJS App. I need to implement a custom service named 'countryservice' for it. Following is my code. var countryApp = angular.module('countryApp', []); countryApp.service('countryservice', function ($http) { this.getallcountries = function ($http) { $http.get('js/countries.json').success(function (data) { return data; }); } }); countryApp.controller('CountryCtrl', function ($http, $scope, countryservice) { $scope.countries = countryservice.getallcountries(

Resolve login in $routeProvider using controller

半世苍凉 提交于 2019-12-12 18:09:37
问题 I'm trying to restrict a user's access to a /topics view and a /question view. I have a login form on the home page. My HomeCtrl has the following login function: $scope.doLogin = function() { var user = { username: $scope.username, password: $scope.password } $http.post('data/user/users.json', user ).success(function(data, status, headers, config) { userService.isAuthenticated = true; userService.username = data.username; userService.password = data.password; $location.path('/topics');

How to close an Angular-ui-bootstrap uibModal on mouseleave using Factory?

99封情书 提交于 2019-12-12 13:18:56
问题 I've recently switched all our modals directives in our app over to Angular-ui-Bootstrap modals. Much better, however running into a new style of modal which closes on mouseleave instead of a cancel click. this.leaveTag = (tag) => { TagHover.off(); }; this.hoverTag = (tag) => { TagHover.display(); }; Above is the view logic that calls functions inside of our TagHover Factory. Below is the Factory, the TagHover.display works fine like with our other modals, but what I'm trying to do with the

Angular store value to service to acces on multiple pages

余生颓废 提交于 2019-12-12 09:56:59
问题 SOLUTION: It seemed that my .get() function invoked before I could update the variable 'something' and therefore it didn't show the updated variable. When I tested it on the real page it worked like a charm :) final FIDDLE note: I did add a return to the set function to immediately update the view. UPDATE: got my factory working alright but can't get the value bound to the factory .set() function. FIDDLE I’m building a manual to install a USB-network connector and need to store some variables

Getting AngularJS Error: “[$rootScope:inprog] $digest already in progress” without a manual $apply

六月ゝ 毕业季﹏ 提交于 2019-12-12 09:33:26
问题 Other posts on this error always include someone trying to $apply without using a safe apply, but that's not the case in my example. My function IS successfully returning the data I requested from the API, but I can't clean this bug and it's driving me nuts. Every time before the .success is called in my $http function I get "Error: [$rootScope:inprog] $digest already in progress" in the console. Below are my controller and service. Thanks! Here's my service including a function to post an

Angular bind service property to a controller scope

不想你离开。 提交于 2019-12-12 09:12:40
问题 I have 2 controllers using the same service, the first controller change the value of a property on the service, I need the second controller to know the property has changed to set the new value in his current $scope. I dont want to use broadcast, is there an elegant way to do this ? Thank you. 回答1: You could create an object in angular service,that will have various shareable properties in it. You could directly assign that variable with your controller scope variable. So that the reference

Share async data between controllers without making multiple requests

不羁岁月 提交于 2019-12-12 07:49:08
问题 I'm trying to make a single $http request to get one of my JSON files and use the data across all my controllers. I saw on egghead.io how to share data across multiple controllers, and I've also read this StackOverflow question: "Sharing a variable between controllers in angular.js". However, the answers there don't use the $http module. When using $http , the controllers don't have the data to work on, and by the time the response is received it's already too late. I then found the method $q

Angularjs photo album

青春壹個敷衍的年華 提交于 2019-12-12 04:53:23
问题 Hi I'm making a photoalbum app with angularjs which grabs base-64 encoded image strings from my server and decodes them into images. The problem is my angularjs app can't seem to decode the base64 strings. On my template it shows the no image found icon. I checked the base64 strings and its fine when I embed it straight to the template like this: <p><img src="data:image/jpeg;charset=utf-8;base64, /9j/4AAQSkZJRgABAQEBLA...etc.</p>' The image will show up. However I need to grab the photoalbum

How do I use a legacy javascript library as a scoped dependency of an Angular service?

不羁的心 提交于 2019-12-11 23:13:25
问题 Specifically, I am working with an ~800 line SCORM API wrapper library that facilitates communication with an LMS. The author did not write it in Angular. A legacy, vanilla js file(index.js) has been wrapped over top of it I'm including a snippet of both to give an idea of the structure being used here. SCORM = { //Define the SCORM object version: null, //Store SCORM version. handleCompletionStatus: true, //Whether or not the wrapper should automatically handle the initial completion status

angularJS $stateParams in service

让人想犯罪 __ 提交于 2019-12-11 19:13:04
问题 I try to fetch JSON data on the page post/:postId within the following factory in my service : angular.module('sampleapp.services', []) .factory('DetailService', function($http) { return { getDetail: function(callback) { $http.get('https://example.com/posts/' + $stateParams.postId + '.json').success(callback); } }; }); Unfortunately, $stateParams is undefined. What am I doing wrong? If I hardcode the URL, it works. My routing : .state('detail', { url: '/post/:postId', templateUrl: 'templates