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

Commit 9627c4b

Browse files
alkismhevery
authored andcommitted
Add ng:src and ng:href markup.
1 parent 293f34c commit 9627c4b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/markups.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ angularTextMarkup('OPTION', function(text, textNode, parentElement){
6969
});
7070

7171
var NG_BIND_ATTR = 'ng:bind-attr';
72+
var SPECIAL_ATTRS = {'ng:src': 'src', 'ng:href': 'href'};
7273
angularAttrMarkup('{{}}', function(value, name, element){
7374
// don't process existing attribute markup
7475
if (angularDirective(name) || angularDirective("@" + name)) return;
@@ -79,7 +80,7 @@ angularAttrMarkup('{{}}', function(value, name, element){
7980
if (hasBindings(bindings)) {
8081
element.removeAttr(name);
8182
bindAttr = fromJson(element.attr(NG_BIND_ATTR) || "{}");
82-
bindAttr[name] = value;
83+
bindAttr[SPECIAL_ATTRS[name] || name] = value;
8384
element.attr(NG_BIND_ATTR, toJson(bindAttr));
8485
}
8586
});

test/markupSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ describe("markups", function(){
4747
expect(sortedHtml(element).replace(' selected="true"', '')).toEqual('<select name="x"><option value="a">a</option></select>');
4848
});
4949

50+
it('should bind href', function() {
51+
compile('<a ng:href="{{url}}"></a>');
52+
expect(sortedHtml(element)).toEqual('<a ng:bind-attr="{"href":"{{url}}"}"></a>');
53+
});
54+
55+
it('should bind src', function() {
56+
compile('<img ng:src="{{url}}" />');
57+
expect(sortedHtml(element)).toEqual('<img ng:bind-attr="{"src":"{{url}}"}"></img>');
58+
});
59+
60+
it('should bind href and merge with other attrs', function() {
61+
compile('<a ng:href="{{url}}" rel="{{rel}}"></a>');
62+
expect(sortedHtml(element)).toEqual('<a ng:bind-attr="{"href":"{{url}}","rel":"{{rel}}"}"></a>');
63+
});
5064
});
5165

5266

0 commit comments

Comments
 (0)