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

Commit 13bab70

Browse files
author
Jason Bedard
committed
fixup! feat($compile): add support for arbitrary property and event bindings
1 parent 7157abe commit 13bab70

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

src/ng/compile.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3494,11 +3494,16 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
34943494
return $sce.valueOf(val);
34953495
});
34963496

3497-
return function ngPropPreLinkFn(scope, $element) {
3498-
scope.$watch(ngPropWatch, function propertyWatchActionFn() {
3499-
var value = ngPropGetter(scope);
3500-
$element.prop(propName, sanitizer(value));
3501-
});
3497+
return {
3498+
pre: function ngPropPreLinkFn(scope, $element) {
3499+
function applyPropValue() {
3500+
var propValue = ngPropGetter(scope);
3501+
$element.prop(propName, sanitizer(propValue));
3502+
}
3503+
3504+
applyPropValue();
3505+
scope.$watch(ngPropWatch, applyPropValue);
3506+
}
35023507
};
35033508
}
35043509
});

test/ng/ngPropSpec.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ describe('ngProp*', function() {
5757
it('should work with different prefixes', inject(function($rootScope, $compile) {
5858
$rootScope.name = 'Misko';
5959
var element = $compile('<span ng:prop:test="name" ng-Prop-test2="name" ng_Prop_test3="name"></span>')($rootScope);
60-
expect(element.prop('test')).toBeUndefined();
61-
expect(element.prop('test2')).toBeUndefined();
62-
expect(element.prop('test3')).toBeUndefined();
63-
$rootScope.$digest();
6460
expect(element.prop('test')).toBe('Misko');
6561
expect(element.prop('test2')).toBe('Misko');
6662
expect(element.prop('test3')).toBe('Misko');
@@ -77,12 +73,6 @@ describe('ngProp*', function() {
7773
$rootScope.name = 'Misko';
7874
var element = $compile('<span data-ng-prop-test2="name" x-ng-prop-test3="name" data-ng:prop-test4="name" ' +
7975
'x_ng-prop-test5="name" data:ng-prop-test6="name"></span>')($rootScope);
80-
expect(element.prop('test2')).toBeUndefined();
81-
expect(element.prop('test3')).toBeUndefined();
82-
expect(element.prop('test4')).toBeUndefined();
83-
expect(element.prop('test5')).toBeUndefined();
84-
expect(element.prop('test6')).toBeUndefined();
85-
$rootScope.$digest();
8676
expect(element.prop('test2')).toBe('Misko');
8777
expect(element.prop('test3')).toBe('Misko');
8878
expect(element.prop('test4')).toBe('Misko');
@@ -117,7 +107,6 @@ describe('ngProp*', function() {
117107
});
118108
inject(function($compile, $rootScope) {
119109
$compile('<div attr-exposer ng-prop-title="12" ng-prop-super-title="34" ng-prop-my-camel_title="56">')($rootScope);
120-
$rootScope.$digest();
121110

122111
expect(attrs.title).toBeUndefined();
123112
expect(attrs.$attr.title).toBeUndefined();
@@ -147,7 +136,6 @@ describe('ngProp*', function() {
147136
});
148137
inject(function($compile, $rootScope) {
149138
$compile('<div attr-exposer ng-prop-title="42" ng-attr-title="foo" title="bar">')($rootScope);
150-
$rootScope.$apply();
151139
expect(attrs.title).toBe('foo');
152140
expect(attrs.$attr.title).toBe('title');
153141
expect(attrs.$attr.ngPropTitle).toBe('ng-prop-title');
@@ -166,7 +154,7 @@ describe('ngProp*', function() {
166154
'$compile', 'nodomevents', 'Property bindings for HTML DOM event properties are disallowed');
167155
}));
168156

169-
it('should process property bindings at $watch time', function() {
157+
it('should process property bindings in pre-linking phase at priority 100', function() {
170158
module(provideLog);
171159
module(function($compileProvider) {
172160
$compileProvider.directive('propLog', function(log, $rootScope) {
@@ -205,11 +193,10 @@ describe('ngProp*', function() {
205193
});
206194
inject(function($rootScope, $compile, log) {
207195
var element = $compile('<div prop-log-high-priority prop-log ng-prop-my_name="name"></div>')($rootScope);
208-
log('postCompile=' + element.prop('myName'));
209196
$rootScope.name = 'angular';
210197
$rootScope.$apply();
211198
log('digest=' + element.prop('myName'));
212-
expect(log).toEqual('compile=undefined; preLinkP101=undefined; preLinkP0=undefined; postLink=undefined; postCompile=undefined; digest=angular');
199+
expect(log).toEqual('compile=undefined; preLinkP101=undefined; preLinkP0=pre101; postLink=pre101; digest=angular');
213200
});
214201
});
215202

@@ -730,7 +717,7 @@ describe('ngProp*', function() {
730717
module(function($provide) {
731718
$provide.decorator('$sce', function($delegate) {
732719
$delegate.trustAsHtml = function(html) { return new MySafeHtml(html); };
733-
$delegate.getTrusted = function(type, mySafeHtml) { return mySafeHtml.val; };
720+
$delegate.getTrusted = function(type, mySafeHtml) { return mySafeHtml && mySafeHtml.val; };
734721
$delegate.valueOf = function(v) { return v instanceof MySafeHtml ? v.val : v; };
735722
return $delegate;
736723
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy