1
1
import angular from 'angular' ;
2
2
3
+ /**
4
+ * Sets attribute with optional value.
5
+ * Does not owerwrite.
6
+ * @param {Array } nodes nodes
7
+ * @param {String } attr attribute name
8
+ * @param {String } val atrtibute value
9
+ */
3
10
function addIfNotPresent ( nodes , attr , val ) {
4
11
angular . forEach ( nodes , ( node ) => {
5
12
if ( ! node . getAttribute ( attr ) ) {
@@ -8,18 +15,32 @@ function addIfNotPresent(nodes, attr, val) {
8
15
} ) ;
9
16
}
10
17
18
+ /**
19
+ * Gets all ngModels from node
20
+ */
11
21
function getNgModelNodes ( node ) {
12
- const query = " [ng-model], [data-ng-model]" ;
22
+ const query = ' [ng-model], [data-ng-model]' ;
13
23
14
- return node . querySelectorAll ( query )
24
+ return node . querySelectorAll ( query ) ;
15
25
}
16
26
27
+ /**
28
+ * Adds attribute with optional value to all elements using ngModel directive.
29
+ * Handles extras.skipNgModelAttrsManipulator
30
+ * And does not overwrite attriutes
31
+ *
32
+ * @param {String } template Template provided by formly template manipulator
33
+ * @param {Object } options Options provided by formly template manipulator
34
+ * @param {String } attrName Attribute's name
35
+ * @param {String|undefined } Attribute's value (optional)
36
+ * @return {String } result
37
+ */
17
38
export function ngModelAttrsManipulator ( template , options , attrName , attrValue ) {
18
39
const node = document . createElement ( 'div' ) ;
19
40
const skip = options . extras && options . extras . skipNgModelAttrsManipulator ;
20
41
21
42
if ( skip === true ) {
22
- return template
43
+ return template ;
23
44
}
24
45
node . innerHTML = template ;
25
46
const modelNodes = getNgModelNodes ( node ) ;
0 commit comments