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

Commit 5502713

Browse files
committed
refactor(ngBindAttr): remove
Breaks ng-bind-attr directive removed
1 parent 09e175f commit 5502713

File tree

4 files changed

+0
-166
lines changed

4 files changed

+0
-166
lines changed

src/AngularPublic.js

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ function publishExternalAPI(angular){
7474
ngBindHtml: ngBindHtmlDirective,
7575
ngBindHtmlUnsafe: ngBindHtmlUnsafeDirective,
7676
ngBindTemplate: ngBindTemplateDirective,
77-
ngBindAttr: ngBindAttrDirective,
7877
ngClass: ngClassDirective,
7978
ngClassEven: ngClassEvenDirective,
8079
ngClassOdd: ngClassOddDirective,

src/directive/ngBind.js

-95
Original file line numberDiff line numberDiff line change
@@ -153,98 +153,3 @@ var ngBindTemplateDirective = ['$interpolate', function($interpolate) {
153153
});
154154
}
155155
}];
156-
157-
158-
/**
159-
* @ngdoc directive
160-
* @name angular.module.ng.$compileProvider.directive.ng-bind-attr
161-
* @restrict A
162-
*
163-
* @description
164-
* The `ng-bind-attr` attribute specifies that a
165-
* {@link guide/dev_guide.templates.databinding databinding} should be created between a particular
166-
* element attribute and a given expression. Unlike `ng-bind`, the `ng-bind-attr` contains one or
167-
* more JSON key value pairs; each pair specifies an attribute and the
168-
* {@link guide/dev_guide.expressions expression} to which it will be mapped.
169-
*
170-
* Instead of writing `ng-bind-attr` statements in your HTML, you can use double-curly markup to
171-
* specify an <tt ng-non-bindable>{{expression}}</tt> for the value of an attribute.
172-
* At compile time, the attribute is translated into an
173-
* `<span ng-bind-attr="{attr:expression}"></span>`.
174-
*
175-
* The following HTML snippet shows how to specify `ng-bind-attr`:
176-
* <pre>
177-
* <a ng-bind-attr='{"href":"http://www.google.com/search?q={{query}}"}'>Google</a>
178-
* </pre>
179-
*
180-
* This is cumbersome, so as we mentioned using double-curly markup is a prefered way of creating
181-
* this binding:
182-
* <pre>
183-
* <a href="http://www.google.com/search?q={{query}}">Google</a>
184-
* </pre>
185-
*
186-
* During compilation, the template with attribute markup gets translated to the ng-bind-attr form
187-
* mentioned above.
188-
*
189-
* _Note_: You might want to consider using {@link angular.module.ng.$compileProvider.directive.ng-href ng-href} instead of
190-
* `href` if the binding is present in the main application template (`index.html`) and you want to
191-
* make sure that a user is not capable of clicking on raw/uncompiled link.
192-
*
193-
*
194-
* @element ANY
195-
* @param {string} ng-bind-attr one or more JSON key-value pairs representing
196-
* the attributes to replace with expressions. Each key matches an attribute
197-
* which needs to be replaced. Each value is a text template of
198-
* the attribute with the embedded
199-
* <tt ng-non-bindable>{{expression}}</tt>s. Any number of
200-
* key-value pairs can be specified.
201-
*
202-
* @example
203-
* Enter a search string in the Live Preview text box and then click "Google". The search executes instantly.
204-
<doc:example>
205-
<doc:source>
206-
<script>
207-
function Ctrl($scope) {
208-
$scope.query = 'AngularJS';
209-
}
210-
</script>
211-
<div ng-controller="Ctrl">
212-
Google for:
213-
<input type="text" ng-model="query" ng-model-instant>
214-
<a ng-bind-attr='{"href":"http://www.google.com/search?q={{query}}"}'>
215-
Google
216-
</a> (ng-bind-attr) |
217-
<a href="http://www.google.com/search?q={{query}}">Google</a>
218-
(curly binding in attribute val)
219-
</div>
220-
</doc:source>
221-
<doc:scenario>
222-
it('should check ng-bind-attr', function() {
223-
expect(using('.doc-example-live').element('a').attr('href')).
224-
toBe('http://www.google.com/search?q=AngularJS');
225-
using('.doc-example-live').input('query').enter('google');
226-
expect(using('.doc-example-live').element('a').attr('href')).
227-
toBe('http://www.google.com/search?q=google');
228-
});
229-
</doc:scenario>
230-
</doc:example>
231-
*/
232-
233-
var ngBindAttrDirective = ['$interpolate', function($interpolate) {
234-
return function(scope, element, attr) {
235-
var lastValue = {};
236-
var interpolateFns = {};
237-
scope.$watch(function() {
238-
var values = scope.$eval(attr.ngBindAttr);
239-
for(var key in values) {
240-
var exp = values[key],
241-
fn = (interpolateFns[exp] ||
242-
(interpolateFns[values[key]] = $interpolate(exp))),
243-
value = fn(scope);
244-
if (lastValue[key] !== value) {
245-
attr.$set(key, lastValue[key] = value);
246-
}
247-
}
248-
});
249-
}
250-
}];

test/BinderSpec.js

-37
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,6 @@ describe('Binder', function() {
4949
expect(element.text()).toBe('123');
5050
}));
5151

52-
it('AttributesNoneBound', inject(function($rootScope, $compile) {
53-
var a = $compile('<a href="abc" foo="def"></a>')($rootScope);
54-
expect(a[0].nodeName).toBe('A');
55-
expect(a.attr('ng-bind-attr')).toBeFalsy();
56-
}));
57-
58-
it('AttributesAreEvaluated', inject(function($rootScope, $compile) {
59-
var a = $compile('<a ng-bind-attr=\'{"a":"a", "b":"a+b={{a+b}}"}\'></a>')($rootScope);
60-
$rootScope.$eval('a=1;b=2');
61-
$rootScope.$apply();
62-
expect(a.attr('a')).toBe('a');
63-
expect(a.attr('b')).toBe('a+b=3');
64-
}));
65-
6652
it('InputTypeButtonActionExecutesInScope', inject(function($rootScope, $compile) {
6753
var savedCalled = false;
6854
element = $compile(
@@ -414,29 +400,6 @@ describe('Binder', function() {
414400
expect(optionC.text()).toEqual('C');
415401
}));
416402

417-
it('DeleteAttributeIfEvaluatesFalse', inject(function($rootScope, $compile) {
418-
element = $compile(
419-
'<div>' +
420-
'<input ng-model="a0" ng-bind-attr="{disabled:\'{{true}}\'}">' +
421-
'<input ng-model="a1" ng-bind-attr="{disabled:\'{{false}}\'}">' +
422-
'<input ng-model="b0" ng-bind-attr="{disabled:\'{{1}}\'}">' +
423-
'<input ng-model="b1" ng-bind-attr="{disabled:\'{{0}}\'}">' +
424-
'<input ng-model="c0" ng-bind-attr="{disabled:\'{{[0]}}\'}">' +
425-
'<input ng-model="c1" ng-bind-attr="{disabled:\'{{[]}}\'}">' +
426-
'</div>')($rootScope);
427-
$rootScope.$apply();
428-
function assertChild(index, disabled) {
429-
expect(!!childNode(element, index).attr('disabled')).toBe(disabled);
430-
}
431-
432-
assertChild(0, true);
433-
assertChild(1, false);
434-
assertChild(2, true);
435-
assertChild(3, false);
436-
assertChild(4, true);
437-
assertChild(5, false);
438-
}));
439-
440403
it('ItShouldSelectTheCorrectRadioBox', inject(function($rootScope, $compile) {
441404
element = $compile(
442405
'<div>' +

test/directive/ngBindSpec.js

-33
Original file line numberDiff line numberDiff line change
@@ -77,37 +77,4 @@ describe('ng-bind-*', function() {
7777
expect(fromJson(element.text())).toEqual({key:'value'});
7878
}));
7979
});
80-
81-
82-
describe('ng-bind-attr', function() {
83-
it('should bind attributes', inject(function($rootScope, $compile) {
84-
element = $compile('<div ng-bind-attr="{src:\'http://localhost/mysrc\', alt:\'myalt\'}"/>')($rootScope);
85-
$rootScope.$digest();
86-
expect(element.attr('src')).toEqual('http://localhost/mysrc');
87-
expect(element.attr('alt')).toEqual('myalt');
88-
}));
89-
90-
it('should not pretty print JSON in attributes', inject(function($rootScope, $compile) {
91-
element = $compile('<img alt="{{ {a:1} }}"/>')($rootScope);
92-
$rootScope.$digest();
93-
expect(element.attr('alt')).toEqual('{"a":1}');
94-
}));
95-
96-
it('should remove special attributes on false', inject(function($rootScope, $compile) {
97-
element = $compile('<input ng-bind-attr="{disabled:\'{{disabled}}\', readonly:\'{{readonly}}\', checked:\'{{checked}}\'}"/>')($rootScope);
98-
var input = element[0];
99-
expect(input.disabled).toEqual(false);
100-
expect(input.readOnly).toEqual(false);
101-
expect(input.checked).toEqual(false);
102-
103-
$rootScope.disabled = true;
104-
$rootScope.readonly = true;
105-
$rootScope.checked = true;
106-
$rootScope.$digest();
107-
108-
expect(input.disabled).toEqual(true);
109-
expect(input.readOnly).toEqual(true);
110-
expect(input.checked).toEqual(true);
111-
}));
112-
});
11380
});

0 commit comments

Comments
 (0)