We can get whatever service we like and then call an specific method.
var serviceName = angular.element(document.body).injector().get('serviceName');
serviceName.someMethod();| // http://stackoverflow.com/questions/20252382/how-to-mock-window-location-replace-in-angularjs-unit-test | |
| describe('whatever', function() { | |
| var $window, whatever; | |
| beforeEach(module('services')); | |
| beforeEach(function() { | |
| $window = {location: { replace: jasmine.createSpy()} }; | |
| module(function($provide) { |
| var createPromiseSpy = function(obj, name, method, $q) { | |
| var createdSpy = jasmine.createSpy(name, obj); | |
| var returnObj = {}; | |
| var promise = {}; | |
| if (typeof(method) === 'string') { | |
| var deferred = $q.defer(); | |
| spyOn(createdSpy, method).and.returnValue(deferred.promise); | |
| promise[method] = deferred; | |
| } |
| /** | |
| * supplant() does variable substitution on the string. It scans through the string looking for | |
| * expressions enclosed in { } braces. If an expression is found, use it as a key on the object, | |
| * and if the key has a string value or number value, it is substituted for the bracket expression | |
| * and it repeats. | |
| * | |
| * Written by Douglas Crockford | |
| * http://www.crockford.com/ | |
| */ | |
| String.prototype.supplant = function (o) { |
| (function() { | |
| 'use strict'; | |
| angular | |
| .module('myApp') | |
| .directive('dynamicName', dynamicName); | |
| /** @ngInject */ | |
| function dynamicName($compile) { | |
| // put name from attribute dynamic-name (input or form tag) | |
| var directive = { |
| // function passed into sort to order by obj.key | |
| function compare(a,b) { | |
| if (a.sequence < b.sequence){ | |
| return -1; | |
| } | |
| if (a.sequence > b.sequence){ | |
| return 1; | |
| } | |
| return 0; | |
| } |
| // http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript | |
| // option 1 | |
| function guid() { | |
| function s4() { | |
| return Math.floor((1 + Math.random()) * 0x10000) | |
| .toString(16) | |
| .substring(1); | |
| } | |
| return s4() + s4() + '-' + s4() + '-' + s4() + '-' + | |
| s4() + '-' + s4() + s4() + s4(); |
| (function() { | |
| 'use strict'; | |
| angular.module('someApp').filter('acronym', function(){ | |
| return function(input){ | |
| return input.split(' ').map(function(x){ return x.charAt(0)}).join('').toUpperCase(); | |
| } | |
| }); | |
| }(); |
Virtual host entry in /etc/hosts
127.0.0.1 testwp.dev www.testwp.dev
When try to see it in browser respond with: testwp.dev refused to connect
Check doing a ping and works
ping testwp.dev| var data = { | |
| '0': 'Some content', | |
| '1': 'Another content', | |
| '2': 23 | |
| }; | |
| var newArray = Object.keys(data).map(function(key, index) { | |
| return {label: index + 1, value: data[key]}; | |
| }); |