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

Commit 24c844d

Browse files
cexbrayatbtford
authored andcommitted
fix($parse): fix parsing error with leading space and one time bind
Closes #7640
1 parent 0eb2c2a commit 24c844d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/ng/parse.js

+2
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,8 @@ function $ParseProvider() {
10241024
switch (typeof exp) {
10251025
case 'string':
10261026

1027+
exp = trim(exp);
1028+
10271029
if (exp.charAt(0) === ':' && exp.charAt(1) === ':') {
10281030
oneTime = true;
10291031
exp = exp.substring(2);

test/ng/compileSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -2196,6 +2196,22 @@ describe('$compile', function() {
21962196
})
21972197
);
21982198

2199+
it('should one-time bind if the expression starts with a space and two colons', inject(
2200+
function($rootScope, $compile) {
2201+
$rootScope.name = 'angular';
2202+
element = $compile('<div name="attr: {{::name}}">text: {{ ::name }}</div>')($rootScope);
2203+
expect($rootScope.$$watchers.length).toBe(2);
2204+
$rootScope.$digest();
2205+
expect(element.text()).toEqual('text: angular');
2206+
expect(element.attr('name')).toEqual('attr: angular');
2207+
expect($rootScope.$$watchers.length).toBe(0);
2208+
$rootScope.name = 'not-angular';
2209+
$rootScope.$digest();
2210+
expect(element.text()).toEqual('text: angular');
2211+
expect(element.attr('name')).toEqual('attr: angular');
2212+
})
2213+
);
2214+
21992215

22002216
it('should process attribute interpolation in pre-linking phase at priority 100', function() {
22012217
module(function() {

0 commit comments

Comments
 (0)