File tree Expand file tree Collapse file tree 2 files changed +9
-7
lines changed
Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change 1- import { isUndefined } from "../../shared/utils .js" ;
1+ import { kebabToCamel } from "../../shared/jqlite/jqlite .js" ;
22
33/**
44 * @param {string } source - the name of the attribute to be observed
@@ -10,20 +10,21 @@ export function ngObserveDirective(source, prop) {
1010 restrict : "A" ,
1111 compile : ( ) => ( scope , element ) => {
1212 const targetElement = element [ 0 ] ;
13- if ( isUndefined ( prop ) || prop == "" ) {
13+ if ( prop = == "" ) {
1414 prop = source ;
1515 }
16- if ( ! scope [ prop ] ) {
17- scope [ prop ] = targetElement . getAttribute ( source ) ;
16+ const normalized = kebabToCamel ( prop ) ;
17+ if ( ! scope [ normalized ] ) {
18+ scope [ normalized ] = targetElement . getAttribute ( source ) ;
1819 }
1920
2021 const observer = new MutationObserver ( ( mutations ) => {
2122 const mutation = mutations [ 0 ] ;
2223 const newValue = /** @type {HTMLElement } */ (
2324 mutation . target
2425 ) . getAttribute ( source ) ;
25- if ( scope [ prop ] !== newValue ) {
26- scope [ prop ] = newValue ;
26+ if ( scope [ normalized ] !== newValue ) {
27+ scope [ normalized ] = newValue ;
2728 scope . $digest ( ) ;
2829 }
2930 } ) ;
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ describe("observe", () => {
8989 } ) ;
9090
9191 it ( "should observe attribute changes and update the same scope name if data-update attribute is absent" , ( ) => {
92- $scope . myProp = "" ;
92+ $scope . testAttribute = "" ;
9393 const template = `<div ng-observe-test-attribute></div>` ;
9494 element = $compile ( template ) ( $scope ) ;
9595 $scope . $digest ( ) ;
@@ -107,5 +107,6 @@ describe("observe", () => {
107107
108108 mutationObserverCallback ( [ mutationRecord ] ) ;
109109 expect ( $scope . $digest ) . toHaveBeenCalled ( ) ;
110+ expect ( $scope . testAttribute ) . toBe ( "newValue" ) ;
110111 } ) ;
111112} ) ;
You can’t perform that action at this time.
0 commit comments