2

Is there a way to access a global JavaScript variable in a Angular expression? such as:

ng-disabled="{someJavascriptVariableHere}"

1 Answer 1

1

Angular expressions will look only for variables on the $scope, but if you do something like this in your controller:

// assumes someJavascriptVariableHere exists in the global scope
$scope.someJavascriptVariableHere = someJavascriptVariableHere;

then you can access it.

Sign up to request clarification or add additional context in comments.

1 Comment

This answer is correct, but I wanted to add that the reason you can access a global variable directly inside of an angular expression is because the angular expression is being evaluated in the context of the scope and if the scope or it's parent scopes don't know the global variable then it will implicitly create the variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.