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

refactor($compile): move check for interpolation of on-event attributes to compile time #13267

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2534,19 +2534,19 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
startingTag(node));
}

if (EVENT_HANDLER_ATTR_REGEXP.test(name)) {
throw $compileMinErr('nodomevents',
"Interpolations for HTML DOM event attributes are disallowed. Please use the " +
"ng- versions (such as ng-click instead of onclick) instead.");
}

directives.push({
priority: 100,
compile: function() {
return {
pre: function attrInterpolatePreLinkFn(scope, element, attr) {
var $$observers = (attr.$$observers || (attr.$$observers = createMap()));

if (EVENT_HANDLER_ATTR_REGEXP.test(name)) {
throw $compileMinErr('nodomevents',
"Interpolations for HTML DOM event attributes are disallowed. Please use the " +
"ng- versions (such as ng-click instead of onclick) instead.");
}

// If the attribute has changed since last $interpolate()ed
var newValue = attr[name];
if (newValue !== value) {
Expand Down
6 changes: 3 additions & 3 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7795,17 +7795,17 @@ describe('$compile', function() {
// All interpolations are disallowed.
$rootScope.onClickJs = "";
expect(function() {
$compile('<button onclick="{{onClickJs}}"></script>')($rootScope);
$compile('<button onclick="{{onClickJs}}"></script>');
}).toThrowMinErr(
"$compile", "nodomevents", "Interpolations for HTML DOM event attributes are disallowed. " +
"Please use the ng- versions (such as ng-click instead of onclick) instead.");
expect(function() {
$compile('<button ONCLICK="{{onClickJs}}"></script>')($rootScope);
$compile('<button ONCLICK="{{onClickJs}}"></script>');
}).toThrowMinErr(
"$compile", "nodomevents", "Interpolations for HTML DOM event attributes are disallowed. " +
"Please use the ng- versions (such as ng-click instead of onclick) instead.");
expect(function() {
$compile('<button ng-attr-onclick="{{onClickJs}}"></script>')($rootScope);
$compile('<button ng-attr-onclick="{{onClickJs}}"></script>');
}).toThrowMinErr(
"$compile", "nodomevents", "Interpolations for HTML DOM event attributes are disallowed. " +
"Please use the ng- versions (such as ng-click instead of onclick) instead.");
Expand Down