How to upload file in angularjs e2e protractor testing

This is how I do it: var path = require(‘path’); it(‘should upload a file’, function() { var fileToUpload = ‘../some/path/foo.txt’, absolutePath = path.resolve(__dirname, fileToUpload); element(by.css(‘input[type=”file”]’)).sendKeys(absolutePath); element(by.id(‘uploadButton’)).click(); }); Use the path module to resolve the full path of the file that you want to upload. Set the path to the input type=”file” element. Click on the … Read more

Binary files corrupted – How to Download Binary Files with AngularJS

How to Download Binary Files with AngularJS When downloading binary files, it is important to set the responseType: app.service(‘VerDocServices’,[‘$http’,function($http) { this.downloadFile = function(url, file, urlDir) { var config = { //SET responseType responseType: ‘blob’, params : { file : file, urlDir : urlDir } }; return $http.get(url, config) .then(function(response) { return response.data; }).catch(function(response) { console.log(“ERROR: … Read more

How to use the ‘replace’ feature for custom AngularJS directives?

When you have replace: true you get the following piece of DOM: <div ng-controller=”Ctrl” class=”ng-scope”> <div class=”ng-binding”>hello</div> </div> whereas, with replace: false you get this: <div ng-controller=”Ctrl” class=”ng-scope”> <my-dir> <div class=”ng-binding”>hello</div> </my-dir> </div> So the replace property in directives refer to whether the element to which the directive is being applied (<my-dir> in that case) … Read more

Redirecting to a certain route based on condition

After some diving through some documentation and source code, I think I got it working. Perhaps this will be useful for someone else? I added the following to my module configuration: angular.module(…) .config( [‘$routeProvider’, function($routeProvider) {…}] ) .run( function($rootScope, $location) { // register listener to watch route changes $rootScope.$on( “$routeChangeStart”, function(event, next, current) { if … Read more

How to reload the current state?

I found this to be the shortest working way to refresh with ui-router: $state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams Update for newer versions: $state.reload(); Which is an alias for: $state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: true }); Documentation: https://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state#methods_reload

$rootScope.$broadcast vs. $scope.$emit

tl;dr (this tl;dr is from @sp00m‘s answer below) $emit dispatches an event upwards … $broadcast dispatches an event downwards Detailed explanation $rootScope.$emit only lets other $rootScope listeners catch it. This is good when you don’t want every $scope to get it. Mostly a high level communication. Think of it as adults talking to each other … Read more