I have the following code in which I want to display an alert when a button is clicked:
<!DOCTYPE html> <html> <head> <title></title> </head> <body ng-app> <button ng-click="alert('test')">Display Text</button> <script src="angular.min.js"></script> <script type="text/javascript">document.write("<base href=\"" + document.location + "\" />");</script> <script type="text/javascript"> $scope.alert = function(variable) { alert(variable); }; </script> </body> </html> The console is displaying this as an error: Uncaught ReferenceError: $scope is not defined
$scopeis only defined inside controllers where the$scopeis injected, it can't be used as just a global variable.