Category: Directives

  • How to fix the “Controller ‘ngModel’ required by directive” error

    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 […]

  • How to unit-test a directive with templateURL

    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 […]