您好,登錄后才能下訂單哦!
新項目要用AngularJS,所以抽時間看了點資料,順便記一下
萬能的Hello world
<!doctype html> <html lang="en" ng-app="HelloAngular"> <head> <meta charset="UTF-8"> <script type="text/javascript" src="http://apps.bdimg.com/libs/angular.js/1.4.0-beta.4/angular.min.js"></script> <script type="text/javascript" src="module.js"></script> <title>Document</title> </head> <body> <div id="" class="" ng-controller="helloAngular"> <p>`greeting`.`text`, Angular</p> </div> </body> </html>
module.js
var myModule = angular.module("HelloAngular", []); myModule.controller("helloAngular",['$scope', function HelloAngular($scope){ $scope.greeting = { text: 'Hello' }; } ]);
運行效果
頁面上顯示 Hello, Angular
AngularJS指令
html頁面
<!doctype html> <html lang="en" ng-app="HelloAngular"><!-- ng-app相當于main方法 --> <head> <meta charset="UTF-8"> <script type="text/javascript" src="http://apps.bdimg.com/libs/angular.js/1.4.0-beta.4/angular.min.js"></script> <script type="text/javascript" src="module.js"></script> <title>Document</title> </head> <body> <hello></hello> </body> </html>
JS代碼
var myModule = angular.module("HelloAngular", []); myModule.directive("hello", function(){ return{ restrict: 'E', template: '<div>Hi everyone</div>', replace:true } });
運行效果:頁面顯示 Hi everyone
雙向數據綁定
<!doctype html> <html lang="en" ng-app> <head> <meta charset="UTF-8"> <script type="text/javascript" src="http://apps.bdimg.com/libs/angular.js/1.4.0-beta.4/angular.min.js"></script> <title>Document</title> </head> <body> <input ng-model="greeting.text"> <p>`greeting`.`text`, AngularJS</p> </body> </html>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。