@@ -1403,6 +1403,32 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1403
1403
return debugInfoEnabled ;
1404
1404
} ;
1405
1405
1406
+ /**
1407
+ * @ngdoc method
1408
+ * @name $compileProvider#strictComponentBindingsEnabled
1409
+ *
1410
+ * @param {boolean= } enabled update the strictComponentBindingsEnabled state if provided, otherwise just return the
1411
+ * current strictComponentBindingsEnabled state
1412
+ * @returns {* } current value if used as getter or itself (chaining) if used as setter
1413
+ *
1414
+ * @kind function
1415
+ *
1416
+ * @description
1417
+ * Call this method to enable/disable strict component bindings check. If enabled, the compiler will enforce that
1418
+ * for all bindings of a component that are not set as optional with `?`, an attribute needs to be provided
1419
+ * on the component's HTML tag.
1420
+ *
1421
+ * The default value is false.
1422
+ */
1423
+ var strictComponentBindingsEnabled = false ;
1424
+ this . strictComponentBindingsEnabled = function ( enabled ) {
1425
+ if ( isDefined ( enabled ) ) {
1426
+ strictComponentBindingsEnabled = enabled ;
1427
+ return this ;
1428
+ }
1429
+ return strictComponentBindingsEnabled ;
1430
+ } ;
1431
+
1406
1432
var TTL = 10 ;
1407
1433
/**
1408
1434
* @ngdoc method
@@ -3430,7 +3456,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3430
3456
3431
3457
case '@' :
3432
3458
if ( ! optional && ! hasOwnProperty . call ( attrs , attrName ) ) {
3433
- destination [ scopeName ] = attrs [ attrName ] = undefined ;
3459
+ if ( strictComponentBindingsEnabled ) {
3460
+ throw $compileMinErr ( 'missingattr' ,
3461
+ 'Attribute \'{0}\' of \'{1}\' is non-optional and must be set!' ,
3462
+ attrName , directive . name ) ;
3463
+ } else {
3464
+ destination [ scopeName ] = attrs [ attrName ] = undefined ;
3465
+ }
3434
3466
}
3435
3467
removeWatch = attrs . $observe ( attrName , function ( value ) {
3436
3468
if ( isString ( value ) || isBoolean ( value ) ) {
@@ -3457,7 +3489,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3457
3489
case '=' :
3458
3490
if ( ! hasOwnProperty . call ( attrs , attrName ) ) {
3459
3491
if ( optional ) break ;
3460
- attrs [ attrName ] = undefined ;
3492
+ if ( strictComponentBindingsEnabled ) {
3493
+ throw $compileMinErr ( 'missingattr' ,
3494
+ 'Attribute \'{0}\' of \'{1}\' is non-optional and must be set!' ,
3495
+ attrName , directive . name ) ;
3496
+ } else {
3497
+ attrs [ attrName ] = undefined ;
3498
+ }
3461
3499
}
3462
3500
if ( optional && ! attrs [ attrName ] ) break ;
3463
3501
@@ -3501,7 +3539,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3501
3539
case '<' :
3502
3540
if ( ! hasOwnProperty . call ( attrs , attrName ) ) {
3503
3541
if ( optional ) break ;
3504
- attrs [ attrName ] = undefined ;
3542
+ if ( strictComponentBindingsEnabled ) {
3543
+ throw $compileMinErr ( 'missingattr' ,
3544
+ 'Attribute \'{0}\' of \'{1}\' is non-optional and must be set!' ,
3545
+ attrName , directive . name ) ;
3546
+ } else {
3547
+ attrs [ attrName ] = undefined ;
3548
+ }
3505
3549
}
3506
3550
if ( optional && ! attrs [ attrName ] ) break ;
3507
3551
@@ -3526,6 +3570,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3526
3570
break ;
3527
3571
3528
3572
case '&' :
3573
+ if ( ! hasOwnProperty . call ( attrs , attrName ) && ! optional && strictComponentBindingsEnabled ) {
3574
+ throw $compileMinErr ( 'missingattr' ,
3575
+ 'Attribute \'{0}\' of \'{1}\' is non-optional and must be set!' ,
3576
+ attrName , directive . name ) ;
3577
+ }
3529
3578
// Don't assign Object.prototype method to scope
3530
3579
parentGet = attrs . hasOwnProperty ( attrName ) ? $parse ( attrs [ attrName ] ) : noop ;
3531
3580
0 commit comments