angularjs-service

Can I use $compile in an Angular service directly on a templateUrl instead of on raw HTML or a raw angular.element?

只愿长相守 提交于 2019-12-01 04:07:10
Given the following service that is meant to create a "dialog" element (i.e. a modal): app.service('dialog', ['$document', '$compile', '$rootScope', function($document, $compile, $rootScope) { var body = $document.find('body'); var scope = $rootScope.$new(); this.createDialog = function() { var dialogElem = angular.element('<div ng-include="\'/dialog.html\'"></div>'); $compile(dialogElem)(scope); body.append(dialogElem); }; } ]); which can be utilized in a controller like so: $scope.someFunction = function() { dialog.createDialog(); }; Is there a way that I can use $compile or anything else to

AngularJS: PUT send data with URL but not as JSON data

放肆的年华 提交于 2019-12-01 01:13:04
Here is my UserService angular.module('userServices', ['ngResource']).factory('User', function($resource) { return $resource('/users/:userId', // todo: default user for now, change it {userId: 'bd675d42-aa9b-11e2-9d27-b88d1205c810'}, {update: {method: 'PUT', params:{profile: '@profile'}, isArray: false}} ); }); In my controller, I do $scope.save = function() { $scope.user.$update({profile: $scope.profile}); } But when I see the Network Tab in Chrome, I see Request URL:http://localhost:5000/users/bd675d42-aa9b-11e2-9d27-b88d1205c810?profile=%5Bobject+Object%5D Request Method:PUT Status Code:200

Dirty checking with shared service between controllers, One way works the other does not?

瘦欲@ 提交于 2019-11-30 22:33:37
While attempting to answer a question regarding sharing data between two separate controllers I ran into a question . I usually use services for for this task and began to create a jsfiddle, but I could not get it to work. After a bit of debugging if I created the properties dynamically in setActivePersonWorks(person) the dirty checking worked and the second controller showed the correct value. If I assigned the value in setActivePersonDoesNotWork() it did not. If I used $timeout() I was able to verify that DataService.badPerson did indeed contain the correct data. Am I doing something wrong?

AngularJS [$injector:unpr] Unknown provider

て烟熏妆下的殇ゞ 提交于 2019-11-30 18:53:55
I am trying to inject a service into controller, and i am getting following error: Error: [$injector:unpr] Unknown provider: employeeServiceProvider <- employeeService http://errors.angularjs.org/1.3.0-beta.17/$injector/unpr?p0=employeeServiceProvider%20%3C-%20employeeService at http://localhost:9082/angularJSDemo/js/lib/angular.js:78:12 at http://localhost:9082/angularJSDemo/js/lib/angular.js:3894:19 at Object.getService [as get] Here is plunker for code. Any help would be appreciated. You are repeating angular.module('demoApp', []) everywhere it will clear out any entities attached to the

Dirty checking with shared service between controllers, One way works the other does not?

与世无争的帅哥 提交于 2019-11-30 18:18:40
问题 While attempting to answer a question regarding sharing data between two separate controllers I ran into a question . I usually use services for for this task and began to create a jsfiddle, but I could not get it to work. After a bit of debugging if I created the properties dynamically in setActivePersonWorks(person) the dirty checking worked and the second controller showed the correct value. If I assigned the value in setActivePersonDoesNotWork() it did not. If I used $timeout() I was able

Use $routeParams in service

别来无恙 提交于 2019-11-30 15:20:01
I'm trying to append a query parameter to all API calls which I fetch from the URL. factory('Post', function ($resource, $routeParams) { return $resource('api/posts', {customer_id: $routeParams.customerId}); }) This works the first time the Post service is used but the second time it's injected it has already been initialized and is using the first customer ID even though the URL has changed. How do I make this work as intended? Because services are singletons. That's why you get that behavior. I recommend that do not inject $routeParams as the init params of a service. Instead, inject it in

AngularJS : Directive not able to access isolate scope objects

孤者浪人 提交于 2019-11-30 15:06:04
问题 I am trying to put some default values in my directive with Isolate scope. Basically, I need to do some DOM manipulations using the scope object when my directive is bound. Below is my code: Controller: angular.module('ctrl').controller('TempCtrl', function($scope, $location, $window, $timeout, RestService, CommonSerivce) { $scope.showAppEditWindow = function() { //Binding the directive isolate scope objects with parent scope objects $scope.asAppObj = $scope.appObj; $scope.asAppSubs = $scope

AngularJS: service query returning zero result

一世执手 提交于 2019-11-30 14:41:29
my app.js looks like var app = angular.module('pennytracker', [ '$strap.directives', 'ngCookies', 'categoryServices' ]); app.config(function($routeProvider) { console.log('configuring routes'); $routeProvider .when('/summary', { templateUrl: '../static/partials/summary.html'}) .when('/transactions', { templateUrl: '../static/partials/transaction.html', controller: 'AddTransactionController' }) }); while my app/js/services/categories.js looks like angular.module('categoryServices', ['ngResource']). factory('Category', function($resource){ return $resource( '/categories/:categoryId', {categoryId

How can I extend $q promise in Angularjs with a .success and .error

你说的曾经没有我的故事 提交于 2019-11-30 12:35:29
问题 I wrote this little code in a custom service in AngularJS. In my service: var deferred = $q.defer(); var promise = deferred.promise; deferred.resolve('success'); deferred.reject('error'); /* Handle success and error */ promise.success = function(fn) { promise.then(function(response) { fn(response); }); return promise; }; promise.error = function(fn) { promise.then(null, function(response) { fn(response); }); return promise; }; In my controller: promiseService.myPromise() .success(function

Using Angularjs $http in browser console

独自空忆成欢 提交于 2019-11-30 11:06:30
I've testing AngularJS services in browser console during development for quick verification. The way I inject a service into console is as describe in this question or var $inj = angular.injector(['myApp']); var serv = $inj.get('myService'); serv.doSomething(); That was working perfectly with AngularJS 1.0.7. However, after upgrading to 1.1.5, it doesn't work anymore for services that uses $http service, that no xhr will be sent. I've tested injecting $http directly, it also doesn't work. AngularJS changelog seems to have no record on this issue. May I know what's the problem here? Update: It