# AngularJS - $http Angular use $http handle AJAX behavior. It support method to handle rest API and basic usage. But its default Content-type is application/json
## Basic usage $http({ method: 'GET', // support GET, POST, PUT, DELETE url: '../php/response.php', params: data, // GET method query string data: data, headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, timeout: 30000, // timeout abort AJAX cache: false }). success(function(data, status, headers, config) { // this callback will be called asynchronously // when the response is available console.
...
Category: AngularJS
# AngularJS - do something after ng-repeat 在學習用 AngularJS 的過程中遇到個問題就是 ng-repeat 好厲害喔, code 變得好少喔 但我想再 ng-repeat 完移掉 loading view 要怎麼移啊? 用 setTimeout 跟白癡一樣, 又不知道時間要設多久 只好向 fb 求救 沒想到有人立馬給出解決方案 原文來源 blog
由於對 AngularJS 不是了解的很透徹, 所以在此不詳加說明(原文內有說明) 這裡只上 code
## HTML <div id='list' ng-app="testApp"> <div ng-controller="blogger" > <ul> <li ng-repeat="list in blog" on-last-repeat> {{list.title.$t}} </li> </ul> </div> </div> ## JavaScript var module = angular.module('testApp', []) .directive('onLastRepeat', function() { return function(scope, element, attrs) { if (scope.
...
# AngularJS - routing 這裡不探究 AngularJS 是如何辦到的 基本上就是用 hash #, 也可用 HTML5 的 history API 這裡只有說有哪些用法
## 基本 sample 這寫法是 1.2.16 的寫法, 不保證以後會變(因為在舊版的 AngularJS 寫法不一樣, 差點搞死我, 當升版本後以前的 code run 不出來時最好去官方看文件)
load AngularJS & angular-route AngularJS v1.2.16 angular-route backup
HTML index.html
<!DOCTYPE html> <html ng-app="route"> <head> <meta charset="utf-8"> <title>routing</title> <script src="http://tedshd.lionfree.net/lib/angular_v1.2.16.js"></script> <script src="http://tedshd.lionfree.net/lib/angular-route.js"></script> </head> <body> <h1>A-Mail</h1> <div ng-view></div> </body> <script src="controllers.js"></script> </html> list.html
<table ng-controller="ListController"> <tr> <td><strong>Sender</strong></td> <td><strong>Subject</strong></td> <td><strong>Date</string></td> </tr> <tr ng-repeat="message in messages"> <td>{{message.
...