From c3a41ff9fefe894663c4d4f40a83794521deb14f Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Wed, 6 Jun 2012 13:58:10 -0700
Subject: feat($compile): simplify isolate scope bindings
Changed the isolate scope binding options to:
- @attr - attribute binding (including interpolation)
- =model - by-directional model binding
- &expr - expression execution binding
This change simplifies the terminology as well as
number of choices available to the developer. It
also supports local name aliasing from the parent.
BREAKING CHANGE: isolate scope bindings definition has changed and
the inject option for the directive controller injection was removed.
To migrate the code follow the example below:
Before:
scope: {
myAttr: 'attribute',
myBind: 'bind',
myExpression: 'expression',
myEval: 'evaluate',
myAccessor: 'accessor'
}
After:
scope: {
myAttr: '@',
myBind: '@',
myExpression: '&',
// myEval - usually not useful, but in cases where the expression is assignable, you can use '='
myAccessor: '=' // in directive's template change myAccessor() to myAccessor
}
The removed `inject` wasn't generaly useful for directives so there should be no code using it.
---
test/ng/directive/inputSpec.js | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
(limited to 'test/ng/directive')
diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js
index d7ca7aea..3b511011 100644
--- a/test/ng/directive/inputSpec.js
+++ b/test/ng/directive/inputSpec.js
@@ -4,7 +4,7 @@ describe('NgModelController', function() {
var ctrl, scope, ngModelAccessor, element, parentFormCtrl;
beforeEach(inject(function($rootScope, $controller) {
- var attrs = {name: 'testAlias'};
+ var attrs = {name: 'testAlias', ngModel: 'value'};
parentFormCtrl = {
$setValidity: jasmine.createSpy('$setValidity'),
@@ -17,12 +17,7 @@ describe('NgModelController', function() {
scope = $rootScope;
ngModelAccessor = jasmine.createSpy('ngModel accessor');
ctrl = $controller(NgModelController, {
- $scope: scope, $element: element.find('input'), ngModel: ngModelAccessor, $attrs: attrs
- });
- // mock accessor (locals)
- ngModelAccessor.andCallFake(function(val) {
- if (isDefined(val)) scope.value = val;
- return scope.value;
+ $scope: scope, $element: element.find('input'), $attrs: attrs
});
}));
@@ -32,6 +27,26 @@ describe('NgModelController', function() {
});
+ it('should fail on non-assignable model binding', inject(function($controller) {
+ var exception;
+
+ try {
+ $controller(NgModelController, {
+ $scope: null,
+ $element: jqLite(''),
+ $attrs: {
+ ngModel: '1+2'
+ }
+ });
+ } catch (e) {
+ exception = e;
+ }
+
+ expect(exception.message).
+ toMatch(/Non-assignable model expression: 1\+2 \(\)/);
+ }));
+
+
it('should init the properties', function() {
expect(ctrl.$dirty).toBe(false);
expect(ctrl.$pristine).toBe(true);
--
cgit v1.2.3