Skip to content

Instantly share code, notes, and snippets.

@nahurst
Last active October 10, 2015 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nahurst/40d731240fb4a09598d0 to your computer and use it in GitHub Desktop.
Save nahurst/40d731240fb4a09598d0 to your computer and use it in GitHub Desktop.
Basic Angular Bootstrap Inline Controller
<html ng-app="myApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Basic App</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
</head>
<body ng-controller="TheCtrl">
<style>
</style>
<div class="container">
<div class="row">
<form>
<div class="form-group">
<label for="num">Num</label>
<input ng-model="num" ng-init="num=0" class="form-control">
</div>
<p>{{twice}}</p>
</form>
</div>
</div>
<script type="text/javascript">
var myApp = angular.module('myApp', []);
myApp.controller('TheCtrl', function ($scope) {
$scope.$watch('num', function() {
$scope.twice = $scope.num * 2;
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment