bindToController in unit tests

In Angular 1.3 (see below for 1.4+) Digging into the AngularJS source code I found an undocumented third argument to the $controller service called later (see $controller source). If true, $controller() returns a Function with a property instance on which you can set properties. When you’re ready to instantiate the controller, call the function and … Read more

How to do an angularjs multi-step/wizard form on one page/url

I think the best way of doing this would be to use ng-switch, just one controller, one route, no reload, using variables shared in all steps, like this: <div ng-controller=”stepCtrl”> <div ng-switch=”step”> <div ng-switch-when=”1″> <!– here you can include your step 1 template, or simply just hardcode it here: –> <div ng-include src=”‘…/step1.html'”> <button ng-click=”setStep(1)”></button> … Read more

Can angular and react play together?

Are they really opposing forces? In some sense they are, and in some other sense they aren’t. People are definitely using React inside Angular directives, but they mostly do that to get a performance boost and not because they think React is awesome. And if you’re only looking into React for better performance, you’re really … Read more

How does Angular 2 change detection work?

Angular creates a change detector object (see ChangeDetectorRef) per component, which tracks the last value of each template binding, such as {{service.a}}. By default, after every asynchronous browser event (such as a response from a server, or a click event, or a timeout event), Angular change detection executes and dirty checks every binding using those … Read more

How to set the dynamic controller for directives?

Now it is possible with AngularJS. In directive you just add two new property called controller , name property and also isolate scope is exactly needed here. Important to note in directive scope:{}, //isolate scope controller : “@”, // @ symbol name:”controllerName”, // controller names property points to controller. Working Demo for Setting Dynamic controller … Read more

Changing html5’s source “src” attribute takes no effect wtih angularjs

Here is a couple of angular approaches : 1) Use ng-src= instead of src= The angular docs explain why this works : http://docs.angularjs.org/api/ng.directive:ngSrc During compilation stage, angular will expand the element to include the correct src= attribute. This will change the src attrib of the HTML5 audio element, but unfortunately that is NOT enough to … Read more

AngularJS : How to use one resolve for all the routes of my application

For completeness, here is the whole solution, using angular instead of underscore, with a chainable ‘when’. Nothing new in this code, just combined a bunch of the answers above. var originalWhen = $routeProvider.when; $routeProvider.when = function(path, route) { route.resolve || (route.resolve = {}); angular.extend(route.resolve, { CurrentUser : function(User) { return User.current(); } }); return originalWhen.call($routeProvider, … Read more

Angular.js ng-switch-when not working with dynamic data?

From the docs — Be aware that the attribute values to match against cannot be expressions. They are interpreted as literal string values to match against. For example, ng-switch-when=”someVal” will match against the string “someVal” not against the value of the expression $scope.someVal. So in other words, ng-switch is for hardcoding conditions in your templates. … Read more

How do I fix my generator-angular project so that grunt test works?

I seem to have fixed my problem, for anyone with a similar problem: Within my karma.conf.js I added the following: plugins: [ ‘karma-chrome-launcher’, ‘karma-jasmine’ ], At first I added ‘karma-jasmine’ but was then met with “Can not load “Chrome”, it is not registered!” This was solved by adding ‘karma-chrome-launcher’ as a plug-in Not sure if … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)