Add ng:src and ng:href markup.

This commit is contained in:
Alkis Evlogimenos 2010-09-17 19:44:23 +02:00 committed by Misko Hevery
parent 293f34cd64
commit 9627c4b50e
2 changed files with 16 additions and 1 deletions

View file

@ -69,6 +69,7 @@ angularTextMarkup('OPTION', function(text, textNode, parentElement){
});
var NG_BIND_ATTR = 'ng:bind-attr';
var SPECIAL_ATTRS = {'ng:src': 'src', 'ng:href': 'href'};
angularAttrMarkup('{{}}', function(value, name, element){
// don't process existing attribute markup
if (angularDirective(name) || angularDirective("@" + name)) return;
@ -79,7 +80,7 @@ angularAttrMarkup('{{}}', function(value, name, element){
if (hasBindings(bindings)) {
element.removeAttr(name);
bindAttr = fromJson(element.attr(NG_BIND_ATTR) || "{}");
bindAttr[name] = value;
bindAttr[SPECIAL_ATTRS[name] || name] = value;
element.attr(NG_BIND_ATTR, toJson(bindAttr));
}
});

View file

@ -47,6 +47,20 @@ describe("markups", function(){
expect(sortedHtml(element).replace(' selected="true"', '')).toEqual('<select name="x"><option value="a">a</option></select>');
});
it('should bind href', function() {
compile('<a ng:href="{{url}}"></a>');
expect(sortedHtml(element)).toEqual('<a ng:bind-attr="{"href":"{{url}}"}"></a>');
});
it('should bind src', function() {
compile('<img ng:src="{{url}}" />');
expect(sortedHtml(element)).toEqual('<img ng:bind-attr="{"src":"{{url}}"}"></img>');
});
it('should bind href and merge with other attrs', function() {
compile('<a ng:href="{{url}}" rel="{{rel}}"></a>');
expect(sortedHtml(element)).toEqual('<a ng:bind-attr="{"href":"{{url}}","rel":"{{rel}}"}"></a>');
});
});