Skip to content

Instantly share code, notes, and snippets.

@kristovatlas
Created March 4, 2016 21:52
Show Gist options
  • Save kristovatlas/3b2d0bc8d290531ed231 to your computer and use it in GitHub Desktop.
Save kristovatlas/3b2d0bc8d290531ed231 to your computer and use it in GitHub Desktop.
A simple example of an Angular injection using $scope.$eval
<!-- angular injection using $scope.$eval -->
<!DOCTYPE html>
<html ng-app>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.1.1/angular.js"></script>
<script type="text/javascript">
function MyController($scope) {
$scope.hack_the_planet = function() {
$scope.myoutput = $scope.$eval($scope.myinput);
}
}
</script>
</head>
<body>
<div ng-controller="MyController">
<input type="text" ng-model="myinput" />
<button ng-click="hack_the_planet()">Hack The Planet</button>
<h1 ng-model="myoutput"> {{ myoutput }} </h1>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment