Normally, a variable with Angular $scope must be declared before binding it to the components property, as shown in the following code example.
The variable column[@length] is declared in the script section before it is bound to the value property of the NumericTextBox component. On rendering, NumericTextBox displays the value 50. In case, variable column[@length] is not declared, then script error is thrown.
Sometimes, there may be scenarios where you cannot declare the variables initially. You may create the HTML element at run time or assign values to the properties at run time. In such cases, error may be thrown when the complex variable (object type) is not declared previously. This error can be avoided by using the ngInit directive in the AngularJS. At run time, make use of this directive when you are unable to declare the $scope variable in advance. The ngInit directive allows you to evaluate an expression in the current scope. The following code shows how to declare a variable by using ngInit.
This page will automatically be redirected to the sign-in page in 10 seconds.