Michael Hsu.tw Oct, 2014
NTUIM R02 BAEIR LAB 徐承志
大一計算機概論眼中的網站
第一次載入
第二次載入
大三 Rails 眼中的網站
志志碩一眼中的網站
志志這個暑假眼中的網站
第一次載入
第二次交換資源
A client-side JavaScript Framework.
加入ng-app 屬性: 作用範圍
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular.min.js"></script>
</head>
<body>
...
</body>
</html>
index.html
ng-model: 雙向綁定
<input type="text" ng-model="yourName">
Hello {{yourName}}!
index.html
Angular Expressions
controller, $scope:作用域
<div ng-controller="myController">
<input type="text" ng-model="yourName">
Hello {{yourName}}!
</div>
var app = angular.module("myApp", []);
app.controller("myController", function($scope) {
$scope.yourName = "Mike";
});
index.html
main.js
ng-click:綁定點擊
<button class="btn" ng-click="clickFn()">Click!</button>
app.controller("myController", function($scope) {
$scope.clickFn = function() {
$scope.yourName = "Michael Hsu";
};
});
index.html
main.js
Ajax: $http service
app.controller("myController", function($scope, $http) {
$scope.clickFn = function() {
$http.get("https://2014-ntuim-prepconf.firebaseio.com/Students.json")
.success(function(d) {
$scope.students = d;
});
}
});
main.js
ng-repeat, filter 就是迴圈嘛
<div ng-repeat="s in students | filter: yourName">
{{ s.id }} : {{s.name}}
</div>
index.html
<html ng-app="app">
<body ng-controller="mainCtrl">
<ng-include src="'views/login.html'" ng-show="login" class="my-elm"></ng-include>
<div class="container my-elm" ng-hide="login">
<div ng-include src="'views/header.html'"></div>
<div ng-include src="'views/content.html'" style="margin-left: -40px"></div>
</div> <!-- end container -->
<script src="libs/angular/angular.min.js"></script>
<script src="libs/angular-animate/angular-animate.min.js"></script>
<script src="js/main.js"></script>
<script src="js/services/services.js"></script>
<script src="js/directives/index.js"></script>
<script src="js/controllers/index.js"></script>
</body>
</html>
index.html