Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 20d35f9

Browse files
committed
pete's comments
1 parent 935bb71 commit 20d35f9

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

docs/content/error/ngRef/nonassign.ngdoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ For example, the following expressions are non-assignable:
1919

2020
```
2121

22-
To resolve this error, use a path expression that are assignable:
22+
To resolve this error, use a path expression that is assignable:
2323

2424
```
2525
<my-directive ng-ref="$ctrl.reference"></my-directive>

src/ng/directive/ngRef.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* @restrict A
77
*
88
* @description
9-
* The `ngRef` attribute tells AngularJS to assign the controller of a component (or an element-directive)
10-
* to the given property in the current scope. If no controller exists, the jqlite-wrapped DOM
11-
* element will be added to the scope.
9+
* The `ngRef` attribute tells AngularJS to assign the controller of a component (or a directive)
10+
* to the given property in the current scope. It is also possible to add the jqlite-wrapped DOM
11+
* element to the scope.
1212
*
1313
* If the element with `ngRef` is destroyed `null` is assigned to the property.
1414
*

test/ng/directive/ngRefSpec.js

+22-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ describe('ngRef', function() {
44

55
describe('on a component', function() {
66

7-
var myComponentController, $rootScope, $compile;
7+
var myComponentController, attributeDirectiveController, $rootScope, $compile;
88

99
beforeEach(module(function($compileProvider) {
1010
$compileProvider.component('myComponent', {
@@ -13,6 +13,16 @@ describe('ngRef', function() {
1313
myComponentController = this;
1414
}
1515
});
16+
17+
$compileProvider.directive('attributeDirective', function() {
18+
return {
19+
restrict: 'A',
20+
controller: function() {
21+
attributeDirectiveController = this;
22+
}
23+
};
24+
});
25+
1626
}));
1727

1828
beforeEach(inject(function(_$compile_, _$rootScope_) {
@@ -23,9 +33,9 @@ describe('ngRef', function() {
2333
it('should bind in the current scope the controller of a component', function() {
2434
$rootScope.$ctrl = 'undamaged';
2535

26-
$compile('<my-component ng-ref="myComponent"></my-component>')($rootScope);
36+
$compile('<my-component ng-ref="myComponentRef"></my-component>')($rootScope);
2737
expect($rootScope.$ctrl).toBe('undamaged');
28-
expect($rootScope.myComponent).toBe(myComponentController);
38+
expect($rootScope.myComponentRef).toBe(myComponentController);
2939
});
3040

3141
it('should throw if the expression is not assignable', function() {
@@ -59,6 +69,11 @@ describe('ngRef', function() {
5969
expect($rootScope.myComponent2).toBe(myComponentController);
6070
});
6171

72+
it('should not bind the controller of an attribute directive', function() {
73+
$compile('<my-component attribute-directive-1 ng-ref="myComponentRef"></my-component>')($rootScope);
74+
expect($rootScope.myComponentRef).toBe(myComponentController);
75+
});
76+
6277
it('should not leak to parent scopes', function() {
6378
var template =
6479
'<div ng-if="true">' +
@@ -116,7 +131,7 @@ describe('ngRef', function() {
116131
expect($rootScope.mySpan[0].textContent).toBe('my text');
117132
}));
118133

119-
it('should nullify the dom element value if it is destroyed', inject(function($compile, $rootScope) {
134+
it('should nullify the expression value if the DOM element is destroyed', inject(function($compile, $rootScope) {
120135
var element = $compile('<div><span ng-ref="mySpan">my text</span></div>')($rootScope);
121136
element.children().remove();
122137
expect($rootScope.mySpan).toBe(null);
@@ -185,7 +200,7 @@ describe('ngRef', function() {
185200

186201

187202
it('should bind an attribute-directive controller if ngRefRead="controllerName" is set', function() {
188-
var attrDirective2Controller;
203+
var attrDirective1Controller;
189204

190205
module(function($compileProvider) {
191206
$compileProvider.directive('elementDirective', function() {
@@ -200,7 +215,7 @@ describe('ngRef', function() {
200215
return {
201216
restrict: 'A',
202217
controller: function() {
203-
attrDirective2Controller = this;
218+
attrDirective1Controller = this;
204219
}
205220
};
206221
});
@@ -221,7 +236,7 @@ describe('ngRef', function() {
221236
'ng-ref="myController"' +
222237
'ng-ref-read="$element"></element-directive>')($rootScope);
223238

224-
expect($rootScope.myController).toBe(attrDirective2Controller);
239+
expect($rootScope.myController).toBe(attrDirective1Controller);
225240
});
226241
});
227242

0 commit comments

Comments
 (0)