Skip to content

Instantly share code, notes, and snippets.

@jexchan
Created December 23, 2013 09:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jexchan/8093767 to your computer and use it in GitHub Desktop.
Save jexchan/8093767 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html id="ng-app" ng-app="app">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" />
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-controller="mainCtrl">
<div class="alert">{{test}}</div>
</body>
</html>
//best practice: id="ng-app" 用来解决浏览器兼容问题
//best practice: 注入$scope时最好用现在的数组方式加入
angular.module("app", [])
.controller("mainCtrl", ["$scope", function($scope) {
$scope.test="hello";
}]);
//如果在页面未用 ng-app ,可以手动来声明,但可能带来兼容性上的问题
angular.bootstrap(document.body, ["app"]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment