Using Bootstrap for Angular and Material design for Angular together

If you add both bootstrap & angular-material this is what will happen Both have css which will target your front end elements (e.g. input element, buttons) Each have their own look & feel (i.e. Bootstrap input element is different from Material input element). So, your overall project won’t have one single look & feel. If … Read more

Get value when selected ng-option changes

as Artyom said you need to use ngChange and pass ngModel object as argument to your ngChange function Example: <div ng-app=”App” > <div ng-controller=”ctrl”> <select ng-model=”blisterPackTemplateSelected” ng-change=”changedValue(blisterPackTemplateSelected)” data-ng-options=”blisterPackTemplate as blisterPackTemplate.name for blisterPackTemplate in blisterPackTemplates”> <option value=””>Select Account</option> </select> {{itemList}} </div> </div> js: function ctrl($scope) { $scope.itemList = []; $scope.blisterPackTemplates = [{id:1,name:”a”},{id:2,name:”b”},{id:3,name:”c”}]; $scope.changedValue = function(item) { … Read more

Validate form field only on submit or user input

Use $dirty flag to show the error only after user interacted with the input: <div> <input type=”email” name=”email” ng-model=”user.email” required /> <span ng-show=”form.email.$dirty && form.email.$error.required”>Email is required</span> </div> If you want to trigger the errors only after the user has submitted the form than you may use a separate flag variable as in: <form ng-submit=”submit()” … Read more

angular $q, How to chain multiple promises within and after a for-loop

What you need to use is $q.all which combines a number of promises into one which is only resolved when all the promises are resolved. In your case you could do something like: function outerFunction() { var defer = $q.defer(); var promises = []; function lastTask(){ writeSome(‘finish’).then( function(){ defer.resolve(); }); } angular.forEach( $scope.testArray, function(value){ promises.push(writeSome(value)); … Read more

Angularjs simple file download causes router to redirect

https://docs.angularjs.org/guide/$location#html-link-rewriting In cases like the following, links are not rewritten; instead, the browser will perform a full page reload to the original link. Links that contain target element Example: <a href=”https://stackoverflow.com/ext/link?a=b” target=”_self”>link</a> Absolute links that go to a different domain Example: <a href=”http://angularjs.org/”>link</a> Links starting with “https://stackoverflow.com/” that lead to a different base path when … Read more

How to write a debounce service in AngularJS

Here is a working example of such a service: http://plnkr.co/edit/fJwRER?p=preview. It creates a $q deferred object that will be resolved when the debounced function is finally called. Each time the debounce function is called the promise to the next call of the inner function is returned. // Create an AngularJS service called debounce app.factory(‘debounce’, [‘$timeout’,’$q’, … Read more

Cannot get to $rootScope

You can not ask for instance during configuration phase – you can ask only for providers. var app = angular.module(‘modx’, []); // configure stuff app.config(function($routeProvider, $locationProvider) { // you can inject any provider here }); // run blocks app.run(function($rootScope) { // you can inject any instance here }); See http://docs.angularjs.org/guide/module for more info.

AngularJS best practices for module declaration?

‘Best’ way to declare a module As angular is on the global scope itself and modules are saved to its variable you can access modules via angular.module(‘mymod’): // one file // NOTE: the immediately invoked function expression // is used to exemplify different files and is not required (function(){ // declaring the module in one … Read more