Category: AngularJs 1.x
-
How to fix the “Controller ‘ngModel’ required by directive” error
The ‘controller ngModel required by directive’ error can be confusing when you first come across it, particularly if you get it when running your unit tests. But it’s a simple fix, and obvious when you understand what Angular’s trying to do. Tl;dr This error is caused by a directive with require: ‘^ngModel’ in its definition […]
-
Introducing Untangled Angular Seed – a best practice Angular Seed app that gets out of your way
Larger Angular apps can be difficult to setup due to the many moving parts involved. Various Angular seed apps exist that provide some of the boilerplate code involved, to help you develop your app more quickly. However, what most add in removing the boilerplate you need to write, they take away in adding unneeded complexity, […]
-
How to unit-test a directive with templateURL
It’s best practice to place the HTML of a directive’s partial within its own file, and reference it in the directive’s definition object via the templateUrl property. However, this causes problems in testing, as most testing frameworks provide no access to the local file. This article shows you how to get around this limitation, and […]
-
Understanding AngularJS Promises 2: Promise callbacks or promise.catch()?
AngularJS’s promises library ($q) provides two different patterns for handling success and failure: the callback pattern and the promise chain pattern (promise.then().catch()). In this article, we’ll look in-depth at the two different patterns, and see why you should always use the promise chain pattern, and why the callback pattern is a much abused Anti-Pattern. Tl;dr […]
-
Why ng-controller is an AntiPattern
ng-controller is used to bind a scope to an element in your HTML. But for large applications, it’s an Anti-Pattern that will cause all manner of pain. Avoid!
-
Best practice for using ng-view, ng-include and directives in your app
When creating an AngularJS app, you split your page’s HTML up into fragments with ng-view, ng-includes, and the partials in directives. In this post, we’ll look at what fragments go where.
-
AngularJS Promises Part 1: How the Deferred API controls the Promise
In this first article on AngularJS’s promises, we look at the relationship between the defer object and its promise, and show how the promise’s functions are triggered by the deferred object.