AngularJS基本特性介绍
- - ITeye博客使用AngularJS非常简单,如下:. 以指令ng-app定义AngularJS的作用域,然后引入angular-1.0.1.min.js,这就是AngularJS的Hello World,简单但是无用. HTML执行表达式(Expressions). AngularJS允许在HTML直接执行表达式,如下:.
<!doctype html> <html ng-app> <head> <script src="http://code.angularjs.org/angular-1.0.1.min.js"></script> </head> <body> Hello {{'World'}}! </body> </html>
1+2 = {{1+2}}! #页面会显示 1+2 = 3!
<div ng-init="students = [ {name:'John', age:25, gender:'boy'}, {name:'Joy', age:15, gender:'girl'}, {name:'Mary', age:28, gender:'girl'}, {name:'Sebastian', age:10, gender:'boy'}, {name:'Samantha', age:16, gender:'girl'} ]"> <div data-ng-repeat="student in students"> <h3>{{student.name}}:{{student.age}}</h3> </div> </div>
<div data-ng-repeat="student in students" data-ng-show="student.gender=='boy'"> <h3>{{student.name}}:{{student.age}}</h3> </div>
<div data-ng-repeat="student in students" data-ng-show="student.gender=='boy'" data-ng-switch="student.age >18"> <h3>{{student.name}}:{{student.age}}</h3> <p data-ng-switch-when="true">ADULT</p> </div>
<div data-ng-repeat="student in students"> <h3>{{student.name}}:{{student.age}}</h3> Edit Name: <input type="text" data-ng-model="student.name"> </div>
<div data-ng-repeat="student in students"> <h3>{{student.name|uppercase}}:{{student.age}}</h3> </div>
<html ng-app=“AngularJSSample”>
var AngularJSSample = angular.module('AngularJSSample', []);
var AngularJSSample = angular.module('AngularJSSample', []); AngularJSSample.filter('greet', function() { return function(name) { return 'Hello, ' + name + '!'; }; });
AngularJSSample.config(['$routeProvider', function($routeProvider){ }]) ;
AngularJSSample.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/students', { templateUrl: 'views/students.html', controller: 'studentsController' }).otherwise( { templateUrl: 'views/greeting.html' }) }]);
AngularJSSample.controller(['studentController', function ($scope) { }]);
AngularJSSample.controller(['studentController', function ($scope) { $scope.students = [ {name: 'John', age: 25, gender: 'boy'}, {name: 'Joy', age: 15, gender: 'girl'}, {name: 'Mary', age: 28, gender: 'girl'}, {name: 'Sebastian', age: 10, gender: 'boy'}, {name: 'Samantha', age: 16, gender: 'girl'} ]; }]);