Angular JS: Detect if ng-bind-html finished loading then highlight code syntax

Issue I am using ng-bind-html for binding data that I get from database. <p ng-bind-html=”myHTML”></p> app.controller(‘customersCtrl’, function($scope, $http, $stateParams) { console.log($stateParams.id); $http.get(“api link”+$stateParams.id) .then(function(response) { $scope.myHTML = response.data.content; // this will highlight the code syntax $(‘pre code’).each(function(i, block) { hljs.highlightBlock(block);

Continue reading

ng-bind-html and highlight.js

Issue I’m trying to get syntax highlighting for all code elements inside a dynamically added html which will be added to the current page with ng-bind-html. <div ng-repeat=”activity in activities”> <h3>{{activity.title}}</h3> <div ng-bind-html=”activity.text”> </div> </div> The activity.text variable contains something

Continue reading

angularjs-google-maps – info-window does not work with ng-repeat

Issue I use google maps with ng-map and use markers and info-windows attached to these markers added to the map with ng-repeat. My angular view is the following: <div id=”mapWrap” map-lazy-load=”https://maps.google.com/maps/api/js”> <map center=”current-location” zoom=”9″ on-bounds_changed=”getLocations()”> <marker ng-repeat=”myMarker in myMarkers” clickable=”true”

Continue reading

Google Maps rendering – strange circles cover the map

Issue I’m using the angularjs-google-maps directive, my code looks like this: (function () { define([‘angular’, ‘app’], function (angular, app) { app.directive(‘customMap’, function () { var customMapTemplate = “<div class= \”vertical-collapse\” ng-class=\”{ ‘opened’ : showMap() }\”>” + ” <div map-lazy-load=\”https://maps.google.com/maps/api/js\”” +

Continue reading

Google Maps rendering – strange circles cover the map

Issue I’m using the angularjs-google-maps directive, my code looks like this: (function () { define([‘angular’, ‘app’], function (angular, app) { app.directive(‘customMap’, function () { var customMapTemplate = “<div class= \”vertical-collapse\” ng-class=\”{ ‘opened’ : showMap() }\”>” + ” <div map-lazy-load=\”https://maps.google.com/maps/api/js\”” +

Continue reading

Google Maps rendering – strange circles cover the map

Issue I’m using the angularjs-google-maps directive, my code looks like this: (function () { define([‘angular’, ‘app’], function (angular, app) { app.directive(‘customMap’, function () { var customMapTemplate = “<div class= \”vertical-collapse\” ng-class=\”{ ‘opened’ : showMap() }\”>” + ” <div map-lazy-load=\”https://maps.google.com/maps/api/js\”” +

Continue reading

Google Maps rendering – strange circles cover the map

Issue I’m using the angularjs-google-maps directive, my code looks like this: (function () { define([‘angular’, ‘app’], function (angular, app) { app.directive(‘customMap’, function () { var customMapTemplate = “<div class= \”vertical-collapse\” ng-class=\”{ ‘opened’ : showMap() }\”>” + ” <div map-lazy-load=\”https://maps.google.com/maps/api/js\”” +

Continue reading

Google Maps rendering – strange circles cover the map

Issue I’m using the angularjs-google-maps directive, my code looks like this: (function () { define([‘angular’, ‘app’], function (angular, app) { app.directive(‘customMap’, function () { var customMapTemplate = “<div class= \”vertical-collapse\” ng-class=\”{ ‘opened’ : showMap() }\”>” + ” <div map-lazy-load=\”https://maps.google.com/maps/api/js\”” +

Continue reading

Google Maps rendering – strange circles cover the map

Issue I’m using the angularjs-google-maps directive, my code looks like this: (function () { define([‘angular’, ‘app’], function (angular, app) { app.directive(‘customMap’, function () { var customMapTemplate = “<div class= \”vertical-collapse\” ng-class=\”{ ‘opened’ : showMap() }\”>” + ” <div map-lazy-load=\”https://maps.google.com/maps/api/js\”” +

Continue reading

Google Maps rendering – strange circles cover the map

Issue I’m using the angularjs-google-maps directive, my code looks like this: (function () { define([‘angular’, ‘app’], function (angular, app) { app.directive(‘customMap’, function () { var customMapTemplate = “<div class= \”vertical-collapse\” ng-class=\”{ ‘opened’ : showMap() }\”>” + ” <div map-lazy-load=\”https://maps.google.com/maps/api/js\”” +

Continue reading

Google Maps rendering – strange circles cover the map

Issue I’m using the angularjs-google-maps directive, my code looks like this: (function () { define([‘angular’, ‘app’], function (angular, app) { app.directive(‘customMap’, function () { var customMapTemplate = “<div class= \”vertical-collapse\” ng-class=\”{ ‘opened’ : showMap() }\”>” + ” <div map-lazy-load=\”https://maps.google.com/maps/api/js\”” +

Continue reading

AngularJS $httpBackend expectGET not working

Issue I am writing QUnit tests for an AngularJS factory. Here’s the code for the factory: var app = angular.module(‘App’, []); app.factory(‘$groupFactory’, function($rootScope, $http) { return { ‘getAll’: function(_callback) { $http.get(“get/values/from/server”, { headers: { ‘Content-type’: ‘application/json’ } }).success(function(data, status, headers,

Continue reading

How do I mock $window injected manually in provider private function?

Issue I have the following provider: angular.module(‘MyApp’).provider(‘MyDevice’, function () { var ngInjector = angular.injector([‘ng’]), $window = ngInjector.get(‘$window’); function isMobileDevice () { return (/iPhone|iPod|iPad|Silk|Android|BlackBerry|Opera Mini|IEMobile/) .test($window.navigator.userAgent || $window.navigator.vendor || $window.opera); } this.$get = function () { return { isDesktop: function ()

Continue reading

karma/jasmine/angular toHaveBeenCalledWith is really called

Issue in my app for instance I’ve got $rootScope.$emit(‘loggedin’,data.user); $rootScope.$on(‘loggedin’, function(event,user) { console.log(‘called’); }); in my test spyOn($rootScope, ‘$emit’); var response = { “success”:1, “user”:{ “id”:1, “email”:”lama@test.test”, “fullname”:”Lama user”, “username”:”lamauser”, “groups”:[“Users”] }, “logged”:1 }; $httpBackend.when(‘POST’, ‘/api/v1/user’).respond(200,response); $scope.save(); $httpBackend.flush(); expect($scope.errors.length).toEqual(0); expect($rootScope.$emit).toHaveBeenCalledWith(‘loggedin’,response.user);

Continue reading

karma/angularjs how to test run block with an asynchronous service

Issue How can I test like: init.js lama.system module angular.module(‘lama.system’, []) .config([‘$httpProvider’, function($httpProvider) { // Crossdomain requests not allowed if you want do cors request see filter.php $httpProvider.defaults.headers.common[‘X-Requested-With’] = ‘XMLHttpRequest’; }]) .run([‘$rootScope’, ‘$state’, ‘$log’, ‘Global’,function ($rootScope, $state, $log, Global) {

Continue reading

AngularJS – interval doesn't get flushed

Issue I have the angular service function that I am willing to test: doSomeTask: function (ids, callback) { $http.put(‘/get_job’, {‘ids’: ids}).success(function (data) { var statusCheck = $interval(function() { $http.get(‘check_status?=’ + data.job_id).success(function (data) { if(data.completed) { $interval.cancel(statusCheck); // and do something…

Continue reading

How to mock socket.io with Angular and Jasmine

Issue I’m having trouble figuring out how to correctly mock Socket.io in an Angular application using Jasmine and Karma. Here are the files found in karma.conf.js: ‘bower_components/angular/angular.js’, ‘bower_components/angular-mocks/angular-mocks.js’, ‘bower_components/angular-ui-router/release/angular-ui-router.js’, ‘bower_components/angular-socket-io/socket.js’, ‘bower_components/socket.io-client/socket.io.js’, ‘bower_components/angular-socket-io/mock/socket-io.js’, ‘public/javascripts/*.js’, ‘ng_tests/**/*.js’, ‘ng_tests/stateMock.js’ Here is how my controller

Continue reading

Jasmine/Angular: TypeError: Cannot read property '$modules/$injector' of undefined

Issue I am trying to run jasmine test cases and i am landing on ‘$modules’ of undefined. I am loading unminified and latest versions of libraries as below, <script src=”lib/jquery-2.1.3.js”></script> <script src=”lib/jasmine-2.1.3.js”></script> <script src=”lib/jasmine-html.js”></script> <script src=”lib/boot.js”></script> <script src=”lib/angular-1.3.9.js”></script> <script src=”lib/angular-mocks-1.0.1.js”></script>

Continue reading

Jasmine – Testing if Controller Exists Getting Error

Issue i have a simple controller: app.controller(“RegisterController”, function ($scope, $location) { // Do something }); And all i am trying to do is to test this controller is defined: describe(‘RegisterController’, function() { var $rootScope, $scope, $controller; beforeEach(module(‘myApp’)); beforeEach(inject(function(_$rootScope_, _$controller_){ $rootScope

Continue reading

AngularJS and Jasmine: mocking services

Issue I am having trouble mocking the dependency of the following service “broadcaster” over the service “pushServices”. angular.module(‘broadcaster’, [‘pushServices’]); angular.module(‘broadcaster’).service(‘broadcaster’, [ ‘$rootScope’, ‘$log’, ‘satnetPush’, function ($rootScope, $log, satnetPush) { // .. contents .. }; }; The Jasmine spec is as

Continue reading

ngMockE2E is causing every request mock the moment added to dependency

Issue I have angular.module(“myModule”, [ //Some dependency “ngMockE2E” ]) This is actually mocking template request and throwing error Unexpected request: GET javascripts/custom/utils/templates/global_loader.html No more request expected at $httpBackend (angular-mocks.js?e_a_v=5:1226) at sendReq (angular.js?e_a_v=5:10215) at $get.serverRequest (angular.js?e_a_v=5:9927) at processQueue (angular.js?e_a_v=5:14437) at angular.js?e_a_v=5:14453

Continue reading

How to unit test (using Jasmine) a function in a controller which calls a factory service which returns a promise

Issue In the below SampleController, how do I unit test that postAttributes function calls sampleService.updateMethod. I’m having trouble since the updateMethod returns promise. angular.module(‘sampleModule’) .controller(‘SampleController’, SampleController); SampleController.$inject =[‘sampleService’]; function SampleController(sampleService){ this.postAttributes = function() { sampleService.updateMethod(number,attributes) .then(function(response){ //do something on successful

Continue reading

Angular services not being defined in beforeEach in Karma

Issue I have an Angular Application using Jasmine and Karma for testing. This is my testing class: var data = require(‘./user.mock.js’); describe(‘Service: UserService’, function () { var ServerUrl; var httpBackend; var userService; beforeEach(angular.mock.module(‘myModule’)); beforeEach(angular.mock.inject(function (_userService_, $httpBackend, _ServerUrl_) { userService =

Continue reading

Testing $interval in Jasmine/ Karma

Issue I have a simple factory angular.module(‘myApp.dice’,[]).factory(‘Dice’, [‘$interval’, function($interval){ return { rollDice: function(){ return $interval(function(c){ count++; }, 100, 18, false, 0); } }; }]); In my test case I have describe(‘rolling dice’, function(){ var promise, promiseCalled = false, notify =

Continue reading

Controller is undefined in jasmine test

Issue karma.config.js: module.exports = function(config) { config.set({ basePath: ”, frameworks: [‘jasmine’], files: [ ‘node_modules/angular/angular.min.js’, ‘node_modules/angular-mocks/angular-mocks.js’, ‘node_modules/angular-translate/dist/angular-translate.min.js’, ‘browser/javascripts/*.js’, ‘browser/tests/*.spec.js’ ], exclude: [], preprocessors: {}, reporters: [‘progress’], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: [‘Chrome’], singleRun: false, concurrency: Infinity })

Continue reading

How to test $scope in Jasmine test?

Issue I trying to write unit tests for Angularjs with Jasmine. Here is my controller: function HomeController($scope, fav, news, materials) { console.log(‘home controller’); $scope.testMe = true; } module.controller(‘HomeController’, HomeController); And tests describe(‘Home controller tests’, function() { var $rootScope, $scope, controller;

Continue reading