angular
All libraries used, CDNs used:
The code copy is as follows:
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js" type="text/javascript"></script>
.angular's data binding instance, this is the most basic, all branches and leaves of angular start from here:.
The code copy is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js" type="text/javascript"></script>
</head>
<body ng-app="app">
<script type="text/javascript">
var app = angular.module("app",[]);
</script>
<div>
<div>
The most powerful thing about angular is data binding binding
</div>
<div>
<div id="bind" ng-controller="bf">
<input type="text" ng-model="data" />
{{data}}
<script>
app.controller("bf", function($scope) {
$scope.data = "testData";
//$scope.$apply();
});
</script>
</div>
</div>
</div>
</body>
</html>
Through angular, display the corresponding data of the array;.
The code copy is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js" type="text/javascript"></script>
</head>
<body ng-app="app">
<script type="text/javascript">
var app = angular.module("app",[]);
</script>
<div>
<div>
Through angular, display the corresponding data of the array;
</div>
<div>
<div id="arr-bind" ng-app="arr-app" ng-controller="arrCon">
<style>
.s{
color:#f00;
}
li{
cursor: pointer;
}
</style>
<ul>
<li ng-repeat="i in lists" ng-click="bered($index)" ng-class="{s : $index == flag}">
{{i.name}}----{{i.age}}
</li>
</ul>
<script>
//angular.module("arr-app", []);
function arrCon($scope) {
$scope.flag = 0;
$scope.bered = function(i) {
$scope.flag = i;
};
$scope.lists = [
{name : "hehe",
age:10},
{
name : "xx",
age : 20
},
{
name : "yy",
age : 2
},
{
name : "jj",
age : 220
}
]
};
</script>
</div>
</div>
</div>
</body>
</html>
DEMO of data filter:
The code copy is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js" type="text/javascript"></script>
</head>
<body ng-app="app">
<script type="text/javascript">
var app = angular.module("app",[]);
</script>
<div>
<div>
Data filter;
</div>
<div ng-controller="filte">
{{sourCode}}
<br>
{{sourCode | up}}
</div>
<script>
function filter($scope) {
$scope.sourCode = "hehe lala dudu oo zz";
};
app.filter("up" ,function() {
return function(ipt) {
return ipt.replace(/ (/w)/g,function($0,$1) {
return " "+$1.toUpperCase();
});
}
});
</script>
</div>
</body>
</html>
.factory factory, $provider, service, etc. are all the same. Don’t feel it’s difficult. In fact, it’s just to see a data model or instance;:
The code copy is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js" type="text/javascript"></script>
</head>
<body ng-app="app">
<script type="text/javascript">
var app = angular.module("app",[]);
</script>
<div id="factory">
<div>
The factory in angular is equivalent to a common instance method, which can be understood as a function that can be used by multiple controllers;
</div>
<div ng-controller="factory">
{{json}}
<script>
app.factory("ff", function() {
return {
"noting" : "json"
};
});
app.controller("factory", function($scope, ff) {
$scope.json = ff;
});
</script>
</div>
</div>
<div>
<div>
angular directive;
</div>
<div>
<heh>do you content for?</heh>
<script>
app.directive("heh", function() {
return {
restrict : "AE",
replace : true,
transclude : true,
template : '<div> <button ng-transclude></button></div>'
};
})
</script>
</div>
</div>
</body>
</html>
The use of .ng-switch directive (I really want this template, which is the angular of our common clicks to hide and display the Tab plug-in first)::
The code copy is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js" type="text/javascript"></script>
</head>
<body ng-app="app">
<script type="text/javascript">
var app = angular.module("app",[]);
</script>
<div>
<div>
Use of ng-switch
</div>
<div ng-controller="sw">
<div ng-init="a=2">
<ul ng-switch on="a">
<li ng-switch-when="1">1</li>
<li ng-switch-when="2">2</li>
<li ng-switch-default>other</li>
</ul>
</div>
<div>
<button ng-click="a=1">test</button>
<button ng-click="a=2">test</button>
<button ng-click="a=3">test</button>
</div>
</div>
<script type="text/javascript">
app.controller("sw", function($scope) {
});
</script>
</div>
</body>
</html>
ng-src and ng-href;
The code copy is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js" type="text/javascript"></script>
</head>
<body ng-app="app">
<script type="text/javascript">
var app = angular.module("app",[]);
</script>
<div>
<div>
Use of ng-src and ng-href (if you use src or href, the HTML will be loaded when initializing it, which is definitely not possible)
</div>
<div ng-controller="srcCon">
<a ng-href="{{logo}}" >
<img ng-src="{{logo}}" />
</a>
</div>
<script type="text/javascript">
app.controller("srcCon", function($scope) {
$scope.logo = "http://www.mainbo.com/templets/images/logo.gif";
});
</script>
</div>
</body>
</html>
How to operate the page style, just change the bound data model directly:
The code copy is as follows:
<div>
<div>
angular operates on styles; (jQ is to manually select elements to operate on element styles. angular provides a more method to assign the attributes of the element to a variable, you just need to change this variable)
</div>
<div>
<hehe id="wh" ng-style="{width: w + 'px', height: h + 'px', backgroundColor: '#364'}">
hehe--o(^^)o wow;
</hehe>
</div>
<script type="text/javascript">
app.directive("hehe", function() {
function compile() {
};
return {
link : function($scope, $element) {
var obj = angular.element($element);
//obj.find is not easy to use;
var add = obj[0].getElementsByClassName("add")[0];
var reduce = obj[0].getElementsByClassName("reduce")[0];
angular.element(add).bind("click", function(){
$scope.h = $scope.h+10;
apply();
})
angular.element(reduce).bind("click", function(){
$scope.h = $scope.h-10;
apply();
});
function apply() {
$scope.$apply();
}
return compile;
},
controller : function($scope) {
$scope.w = 200;
$scope.h = 50;
//$scope.$apply();
},
restrict: 'AE',
replace : true,
scope : "=ng-style",
transclude : true,
template : '<div><div ng-transclude></div><button>+</button><button>-</button></div>'
}
})
</script>
</div>
How to use the template in angular? This needs to be used with the router:
The code copy is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js" type="text/javascript"></script>
</head>
<body ng-app="app">
<script type="text/javascript">
var app = angular.module("app",[]);
</script>
<div>
<div>
Using templates
</div>
<div ng-controller="ngTpl">
<!---This type must be declared accurately-->
<script type="text/ng-template" id="tpl">
{{ver}}
</script>
<!---tpl is a fixed value, not a variable, and the variable should be defined in scope--->
<div ng-include src="'tpl'"></div>
<div>
<button ng-click="chan()">change</button>
</div>
</div>
<script type="text/javascript">
app.controller("ngTpl", function($scope) {
function hehe(str) {
str = _.shuffle(str);
return str.join("")
};
$scope.ver = "var-ver--heehe";
$scope.chan = function() {
$scope.ver = hehe( $scope.ver );
};
});
</script>
</div>
</body>
</html>
How to use $scope.$watch to change the template of the binding interface in real time:
The code copy is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js" type="text/javascript"></script>
</head>
<body ng-app="app">
<script type="text/javascript">
var app = angular.module("app",[]);
</script>
<div>
<div>
<span>update</span>angular notification data updates in three ways $scope.$digest(), $scope.$apply(), and updates through $scope.$watch listening;
</div>
<div ng-controller="apply">
{{hehe}}
<input type="text" ng-model="m0" />
<div>
the value set by $scope.$watch ==>> {{wat}}
</div>
<br>
<button ng-click="up()">
apply;
</button>
</div>
<script type="text/javascript">
app.controller("apply", function($scope) {
$scope.hehe = "lll________xxx";
$scope.m0 = 1;
ss = $scope;
$scope.up = function() {
$scope.hehe = $scope.m0;
//Yes, but an error was reported when the prompt was given. Who knows why?
//$scope.$apply();
$scope.$digest();
};
//Give the $scope.m0 variable to be invalid;
$scope.$watch("m0", function(va) {
$scope.wat = va;
})
});
</script>
</div>
</body>
</html>
The tool method you define yourself in angular
The code copy is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js" type="text/javascript"></script>
</head>
<body ng-app="app">
<script type="text/javascript">
var app = angular.module("app",[]);
</script>
<div>
<div>
List of tool method in angular
</div>
<div>
<ul>
<li role="presentation"><a href="###">angular.bind</a></li>
<li role="presentation"><a href="###">angular.bootstrap</a></li>
<li role="presentation"><a href="###">angular.copy</a></li>
<li role="presentation"><a href="###">angular.element</a></li>
<li role="presentation"><a href="###">angular.equals</a></li>
<li role="presentation"><a href="###">angular.extend</a></li>
<li role="presentation"><a href="###">angular.forEach</a></li>
<li role="presentation"><a href="###">angular.fromJson</a></li>
<li role="presentation"><a href="###">angular.identity</a></li>
<li role="presentation"><a href="###">angular.injector</a></li>
<li role="presentation"><a href="###">angular.isArray</a></li>
<li role="presentation"><a href="###">angular.isDate</a></li>
<li role="presentation"><a href="###">angular.isDefined</a></li>
<li role="presentation"><a href="###">angular.isElement</a></li>
<li role="presentation"><a href="###">angular.isFunction</a></li>
<li role="presentation"><a href="###">angular.isNumber</a></li>
<li role="presentation"><a href="###">angular.isObject</a></li>
<li role="presentation"><a href="###">angular.isString</a></li>
<li role="presentation"><a href="###">angular.isUndefined</a></li>
<li role="presentation"><a href="###">angular.lowercase</a></li>
<li role="presentation"><a href="###">angular.module</a></li>
<li role="presentation"><a href="###">angular.noop</a></li>
<li role="presentation"><a href="###">angular.reloadWithDebugInfo</a></li>
<li role="presentation"><a href="###">angular.toJson</a></li>
<li role="presentation"><a href="###">angular.uppercase</a></li>
</ul >
<div>
These tools and methods are similar to other libraries;
angular.element is a small JQ for anguarLite selection element;
<br>
angular.module is a method of module elements;
</div>
</div>
</div>
</body>
</html>
The use of ng-transclude (this is an official case), the code is as follows:
The code copy is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js" type="text/javascript"></script>
</head>
<body ng-app="app">
<script type="text/javascript">
var app = angular.module("app",[]);
</script>
<div>
<div>
Use of ng-transclude (this is an official case):
</div>
<div ng-controller="ExampleController">
<div>
<input ng-model="title"><br>
<textarea ng-model="text"></textarea> <br/>
<pane>{{text}}</pane>
</div>
</div>
<script type="text/javascript">
app.directive('pane', function(){
return {
restrict: 'E',
transclude: true,
scope: { title:'@' },
template: '<div style="border: 1px solid black;">' +
'<div style="background-color: gray">{{title}}</div>' +
'<ng-transclude></ng-transclude>' +
'</div>'
};
})
.controller('ExampleController', ['$scope', function($scope) {
$scope.title = 'Lorem Ipsum';
$scope.text = 'Nequ porno quisquam est qui dolorem ipsum quia dolor...';
}]);
</script>
</div>
</body>
</html>
Here is an example of verifying the accuracy of the mailbox:
The code copy is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js" type="text/javascript"></script>
</head>
<body ng-app="app">
<script type="text/javascript">
var app = angular.module("app",[]);
</script>
<div>
<div>
ngPaste, ngMouseup, ngKeyup, ngModelOptions, etc., refer to the official use, just use the check API, (the official needs FQ;)
</div>
<script src="https://yearofmoo.github.io/ngMessages/angular-messages.js"></script>
<div ng-controller="fromvaild">
If you do not use the ng-message component, the error prompt is as follows;
<form name="userForm">
<div>
<label for="emailAddress">Enter your email address:</label>
<input type="email" name="emailAddress" ng-model="data.email" required />
<!-- this stuff is WAY too complex -->
<div ng-if="userForm.emailAddress.$error.required">
You forgot to enter your email address...
</div>
<div ng-if="!userForm.emailAddress.$error.required &&
userForm.emailAddress.$error.email">
You did not enter your email address correctly...
</div>
</div>
<input type="submit" />
</form>
<br>
<a href="https://yearofmoo.github.io/ngMessages/">DEMO written by foreigners</a>
</div>
<script type="text/javascript">
app.controller("fromvaild", function($scope) {
//$scope.myField.$error = { minlength : true, required : false };
})
</script>
</div>
</body>
</html>
setTimeout and setInterval are both wrapped by angular, and return an instance of the delayed object:
The code copy is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js" type="text/javascript"></script>
</head>
<body ng-app="app">
<script type="text/javascript">
var app = angular.module("app",[]);
</script>
<div>
<div>
$timeout and $interval, these two services;
</div>
<div ng-controller="st">
<div>
<a href="#">
<h4>setInterval</h4>
<p>
$interval(fn, delay, [count], [invokeApply]);
</p>
</a>
<a href="#">
<h4>timeout</h4>
<p>
$timeout(fn, [delay], [invokeApply]);
</p>
</a>
</div>
<div>
<div role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
0%
</div>
</div>
<button ng-click="prog()">
start
</button>
</div>
<script type="text/javascript">
app.controller("st", function($scope,$element,$interval) {
var $el = $($element[0]).find(".progress-bar");
console.log(arguments);
//Use the element selected by angular.element to find something without finding;
$scope.prog = function() {
var df = $interval(function() {
var val = parseInt($el.html())+4;
if(val>=104) $interval.cancel(df);
$el.html( val+"%" ).width(val+"%");
},100);
console.log(df)
//console.log(aa = $interval)
};
});
</script>
</div>
</body>
</html>