標籤:cordova
<!DOCTYPE html><html><head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> <title>test</title></head><body> <div ng-app="myApp" ><!--ang-app 指令告訴 AngularJS, <div> 元素是 AngularJS 應用程式 的"所有者"--> <div> name:<input name="name" ng-model="name"/> <!--ng-model 指令把輸入欄位的值綁定到應用程式變數 name--> </div> <div ng-bind="name"></div><!--指令把應用程式變數 name 綁定到某個段落的 innerHTML。--> {{name}}<!--這裡與上面的model建立了資料雙向繫結 {{}}等同於 ng_bind--> <div ng-init="sex=‘f‘;age=‘23‘;person={name:‘李三‘};number=[5,6];"> <!--指令為 AngularJS 應用程式定義了 初始值 等價於data-ng-init --> {{sex}},{{age}} </div> <div> {{sex}},{{age}} </div> <div> {{person.name}} ; {{number[0]}}+6={{5+6}},{{‘對‘+‘的‘+age}} <!--運算式 很像 JavaScript 運算式:它們可以包含文字、運算子和變數--> </div> <div ng-controller="firstCtl"><!--定義了應用程式控制器--> title:<input name="title" ng-model="title"><!--我們可以把我們的 model 存放在 scope 上,來達到雙向你綁定--> {{title}} </div> <div ng-controller="secondCtl"> <ul> <li ng-repeat="n in numbs"> <!--ng-repeat 是一個迴圈指令--> {{n}} </li> </ul> </div> {{testdata}} </div> <script src="js/angular.js"></script> <script type="text/javascript"> var myApp = angular.module(‘myApp‘, []); myApp.controller(‘firstCtl‘, function($scope) { //控制器的 $scope 是控制器所指向的應用程式 HTML 元素 angular 中$scope 是串連 controllers(控制器)和 templates(模板 view/視圖)的主要膠合體。 $scope.title = ‘Hello‘; }); myApp.run([‘$rootScope‘,function($rootScope){ //只對全域範圍起作用 $rootScope.testdata = ‘heheh‘; }]); myApp.controller(‘secondCtl‘, function($scope , $http) { $scope.numbs = [111,222,333,444]; $http({ method: ‘GET‘, url: ‘http://www.test.com/test2.php‘ }).then(function successCallback(response) { /* response這個對象有如下屬性: data – {string|Object} – 伺服器返回的資料 status – {number} – 響應的 HTTP 狀態代碼 . headers – {function([headerName])} – Header getter function. config – {Object} – The configuration object that was used to generate the request. statusText – {string} – 響應的 HTTP 狀態檔案本. */ console.log(response); }, function errorCallback(response) { console.log(response); }); $http({ method: ‘POST‘, url: ‘http://www.test.com/test2.php‘, data:"test=test22222", headers: { ‘Content-Type‘: ‘application/x-www-form-urlencoded‘ }, }).then(function successCB(response){ console.log(response); },function errorCB(response){ console.log(response); }); $http.post(‘http://www.test.com/test2.php‘, {‘test‘:‘po‘}, {params:{‘te‘:‘te‘}}).then(function(response){ console.log(response); },function(response){ console.log(response); }); }); </script></body></html>
Cordova學習筆記 http及run方法