<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script src="scripts/angular.js"></script>
</head>
<body ng-app="app" ng-controller="cur">
how are you!
<div>
<input type="text" ng-model="name" />
{{name}}
<button ng-click="pop(this)">pop</button>
</div>
<ul>
<li ng-repeat="num in list">{{num}}</li>
</ul>
<select>
<option ng-repeat="no in select" value="{{no}}">{{no}}</option>
</select>
<div ng-show="show()">ng show test</div>
<div ng-show="show1">ng show test boolean</div>
<script>
var app = angular.module('app', []);
app.controller('cur', function ($scope) {
$scope.name = 'test';
$scope.list = [1, 2, 3, 4];
$scope.select = [4, 3, 2, 1];
$scope.pop = function (obj) {
//alert(obj);
alert($scope.name);
}
$scope.show = function () {
return false;
};
$scope.show1 = true;
});
</script>
</body>
</html>

 mark 前端MVVM的实现方案:

整个scope内部的模型,统一由pipe的property change事件来处理,每次触发捕获的change等事件时对比原有scope的data,发现不相同即重新刷新data。 每次执行,均执行整个scope模块init,内部事件全部采用捕获的方式,事件全部绑定在scope最外层。

实现起来与后端mvvm是一致的,如wpf....

自动替换:添加事件检测,捕获change等事件,change之后重新init整个scope.

==section 2016.7.15 deeper practice!

<!DOCTYPE html>
<html>
<head>
<title>calos practising angular!</title>
<meta charset="utf-8" />
<script src="scripts/angular.js"></script>
</head>
<body ng-app="app" ng-controller="cur">
how are you!
<div>
<input type="text" ng-model="name" />
{{name}}
<button ng-disabled="!btndisable" ng-click="pop(this)">pop</button>
<button ng-disabled="btndisable" ng-click="pop(this)">pop</button>
</div>
<ul>
<li ng-repeat="num in list">{{num}}</li>
</ul>
<select ng-model="nameselected" ng-change="changename(this)">
<option ng-repeat="no in select" value="{{no}}">{{no}}</option>
</select>
<div ng-show="show()">ng show test</div>
<div ng-show="show1">ng show test boolean</div>
<div ng-include="'/partials/partial1.html'">
<!--how to use partial: remember to add sing quotation!
like this. but these words will not be displayed!-->
</div>
<a href="#/">/ will show by default!</a>
<a href="#/page1">Nav to page1 under pages folder!</a>
<a href="#/showinfo">Nav to page1 under pages folder!</a>
<a href="#/home">embeded page!</a>
<div ng-view>
<!-- this is a placeholder for routed pages to present! must have the tag ng-view="" -->
</div>
<script type="text/ng-template" id="embeded.home.html">
<h1> Home </h1>
</script> <script src="scripts/angular-route.js"></script>
<script>
var app = angular.module('app', ['ngRoute']) //#region infrastructure this is controllers region before configuring routes
app.controller('cur', function ($scope, $http, $timeout, $interval) {
//there should be a argument name validation in this controller
//injection function, so, 1st name must be $scope, but can use alias inner!
var a = $scope;
a.btndisable = true;
a.name = 'test';
a.list = [1, 2, 3, 4];
a.nameselected = '请选择';
a.select = [4, 3, 2, 1];
a.select = ['请选择'].concat(a.select);
a.pop = function (obj) {
//alert(obj);
alert(a.name);
//below for $http.get practice!
$http.get('/jsons/json.json').success(function (response) {
a.name = response.name;
a.btndisable = (a.btndisable === true ? false : true);
}).then(function (ret) {//the data returned has a wapper including data!
a.name = ret.data.name;
});
}
a.show = function () {
return false;
};
a.changename = function (obj) {
console.log(obj);
a.name = a.name + 'reissue!'
}
a.show1 = true; //$timeout(function () { alert('timeout!') }, 5000);
//$interval(function () { alert('interval') }, 2000);
});
app.controller('page1', function ($scope, $http) {
$scope.name = 'page1 controller';
});
//#endregion app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/', { template: 'Welcome!' })
.when('/page1', { templateUrl: 'pages/page1.html', controller: 'page1' })
.when('/showinfo', { template: 'show pure text!' })
.when('/home', { templateUrl: 'embeded.home.html' })
.otherwise({ redirectTo: '/' });
}]);
</script>
</body>
</html>

match:!

sendRequest($http, api.userGet).success(function (response) {
a.name = response.name;
a.btndisable = (a.btndisable === true ? false : true);
});

  

AngularJs Test demo &front end MVVM implementation conjecture and argue.的更多相关文章

  1. AngularJS入门-demo

    双向绑定测试: <body ng-app> 请输入姓名:<input ng-model="myname"> <br> {{myname}},你好 ...

  2. AngularJS +HTML Demo

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...

  3. AngularJS学习笔记(一) 关于MVVM和双向绑定

    写在前面: 因为需要开始学习ng,之前在知乎上听大神们介绍ng的时候说这个坑如何的大,学了一阵(其实也就三天),感觉ng做的很大很全,在合适的情境你可以完全使用ng搞定一切.这一点从诸如jqLite之 ...

  4. AngularJS入门Demo

    1 :表达式 <html> <head> <title>入门小Demo-1</title> <script src="angular.m ...

  5. angularjs transclude demo

    <!doctype html> <html lang="en" ng-app="expanderModule"> <head> ...

  6. angularjs ngRoute demo

    <!doctype html> <html lang="en" ng-app="AMail"> <head> <met ...

  7. angularjs $watch demo

    <!doctype html> <html lang="en" ng-app> <head> <meta charset="UT ...

  8. AngularJS 下拉列表demo

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...

  9. AngularJS 中文资料+工具+库+Demo 大搜集

    中文学习资料: 中文资料且成系统的就这么多,优酷上有个中文视频. http://www.cnblogs.com/lcllao/archive/2012/10/18/2728787.html   翻译的 ...

随机推荐

  1. java时间格式串

    yyyy-mm-dd 和yyyy-MM-dd转换出来的日期不用. 用"yyyy-MM-dd"

  2. openCV中IplImage的使用

    http://blog.csdn.net/welcome_xu/article/details/7650680 IplImage结构详细分析   IplImage 结构解读: typedef stru ...

  3. sort,ksort,asort的区别

    sort--对数组的val进行排序 ksort--对数组的key值进行排序 asort--对数组进行排序,键与值的对应关系不变 1.sort对数组排序 格式如下:bool sort(array &am ...

  4. php---文件上传分析

    文件上传: 先抄一段:预定义变量$_FILES数组有5个内容:       $_FILES['userfile']['name']——客户端机器文件的原名称       $_FILES['userfi ...

  5. 实验一 Java开发环境的熟悉-刘蔚然

    一.实验内容 1. 使用JDK编译.运行简单的Java程序 2. 使用Eclipse 编辑.编译.运行.调试Java程序 要求: 完成实验.撰写实验报告 统计PSP时间 二.实验过程 使用JDK编译. ...

  6. Magento SSH 下载安装

    http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/installing_magento_via_shell_ ...

  7. C#中value是什么意思

    value是c#中的“属性”例如c#某个类中有一个成员变量(字段),为了安全性,外部如果要访问它,必须通过“属性”来访问:private int _id;//这是一个成员变量,private表示是私有 ...

  8. mobiscroll.js 使用

    使用较为详情的参考网址:http://www.lanrenmaku.com/jMobile/2014_1231_1357.html

  9. iOS:runtime最全的知识总结

    runtime 完整总结 好东西,应该拿出来与大家分享... 南峰子博客地址:http://southpeak.github.io/blog/categories/ios/ 原文链接:http://w ...

  10. saltstack之(六)配置管理state

    配置管理是saltstack工具最重要的模块之一,也是学习saltstack之后使用最多的一个功能.可以轻松实现上百台上千台甚至上万台服务器的管理工作. 1.使用state模块进行配置管理,编写sls ...