Angular学习(6)- 数组双向梆定+filter+directive
示例:
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<title>Study 6</title>
<script type="text/javascript" src="js/angular.js"></script>
</head>
<body>
<div ng-controller="testController">
<h1>{{model.newTitle}}</h1>
Name:<input type="text" ng-model="model.name" />
Fraction:<input type="text" ng-model="model.fraction" fraction-num />
Type:<select ng-model="model.type"><option value="1" selected>Radio</option><option value="2">CheckBox</option></select>
<input type="button" ng-click="add(model.fraction)" value="Add" />
<ul>
<li ng-repeat="item in model.options">
<b>{{$index+1}}</b>
<input type="text" ng-model="item.content" value="item.content" fraction-num />
<a href="javascript:void(0)" ng-click="del($index)">Delete</a>
</li>
</ul>
<hr />
<div>
<h1>{{model.previewTitle}}</h1>
<b>[{{model.type | typeFilter}}]{{model.name}}</b>({{model.fraction}})
<ul>
<li ng-repeat="item in model.options">
<b>{{$index + 1}}</b>
<input type="radio" name="optcheck" ng-show="model.type==1" />
<input type="checkbox" ng-show="model.type==2" />
{{item.content}}
</li>
</ul>
</div>
<hr />
{{nowTime | date : "yyyy-MM-dd HH:mm:ss"}}
</div>
<script type="text/javascript">
var app = angular.module("MyApp", [], function() { });
var myModel = {
newTitle: "Title",
previewTitle: "Preview Title",
name: "Robin",
fraction: "100",
type : 1,
options: []
};
app.controller("testController", function($scope) {
$scope.model = myModel;
$scope.add = function(text) {
var obj = { content: text };
$scope.model.options.push(obj);
};
$scope.del = function(index) {
$scope.model.options.splice(index, 1);
};
$scope.nowTime = new Date();
});
app.filter("typeFilter", function() {
var func = function(value) {
return value == 1 ? "Single Select" : "Multi Select";
};
return func;
});
app.directive("fractionNum", function() {
return {
link: function(scope, elements, attrs, controller) {
elements[0].onkeyup = function() {
if (/\D/.test(this.value)) {
this.style.borderColor = 'red';
}
else {
this.style.borderColor = '';
}
};
}
};
});
</script>
</body>
</html>
Angular学习(6)- 数组双向梆定+filter+directive的更多相关文章
- Angular学习(5)- 数组双向梆定+filter
示例: <!DOCTYPE html> <html ng-app="MyApp"> <head> <title>Study 5< ...
- Angular学习(4)- 数组双向梆定
示例: <!DOCTYPE html> <html ng-app="MyApp"> <head> <title>Study 4< ...
- Angular学习(3)- 双向梆定
示例代码: <!DOCTYPE html> <html ng-app="MyApp"> <head> <title>Study 3& ...
- angular学习的一些小笔记(中)之directive
directive里面的几个配置,上代码就清晰了 <!DOCTYPE html> <html ng-app='app'> <head> <meta chars ...
- 【JS学习】数组过滤方法的使用filter
前言:本博客系列为学习后盾人js教程过程中的记录与产出,如果对你有帮助,欢迎关注,点赞,分享.不足之处也欢迎指正,作者会积极思考与改正. 使用效果: 可以返回参数函数为真的值 //情景:实现从stu数 ...
- Angular 学习笔记——ng-repeat&filter
<!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <met ...
- 【转】Angular学习总结--很详细的教程
*这篇文章是转来的,做了自己的一点修改,排版.原始出处不明,如涉及原博主版权问题,请及时告知,我将会立即删除*. 1 前言 前端技术的发展是如此之快,各种优秀技术.优秀框架的出现简直让人目不暇接,紧跟 ...
- angular学习笔记(三十一)-$location(2)
之前已经介绍了$location服务的基本用法:angular学习笔记(三十一)-$location(1). 这篇是上一篇的进阶,介绍$location的配置,兼容各版本浏览器,等. *注意,这里介绍 ...
- Angular学习资料大全和常用语法汇总(让后端程序员轻松上手)
前言: 首先为什么要写这样的一篇文章呢?主要是因为前段时间写过一些关于Angualr的相关实战文章,有些爱学习的小伙伴对这方面比较感兴趣,但是又不知道该怎么入手(因为认识我的大多数小伙伴都是后端的同学 ...
随机推荐
- 如何在Apache中建立一个新端口
环境: Windows server 2008 R2, Apache, PHP5 步骤: 建立一个目录,里面放置一个index.php. 打开Apache\conf\httpd.conf 文件,做如下 ...
- js中获取样式的俩种方法 style.color和style['color'] 区别
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 阿里云Centos中二级域名绑定二级目录的方法
对于一些目录,我们往往需要对其指定二级域名,那么具体如何操作呢?下面,我将用亲身实践来说明一下. 由于第一次接触centos,我不得不借助于网络资源.然后得知要开启mod_rewrite这个模块,具体 ...
- ~0u >> 1
~ 逐位求反u 后辍为 定义unsigned类型>>右移如在32系统中,连起来就是 将32位的0取反后 右移一位.也就是 int 的最大值 2147482347
- coreseek(sphinx)安装2(mysql数据源配置和测试)
Windows操作系统下 mysql数据源配置: 主要步骤: 配置mysql数据源配置文件->生成索引->开启索引 (三步) coreseek\etc\csft_mysql.conf ...
- linux下ftp常用命令
1. Linux 终端连接FTP $ ftp 10.85.3.12 Name : fxm5547 Password: ftp> 如果FTP 允许匿名用户,那么用户名要输入anonymous,密码 ...
- codeforces hungry sequence 水题
题目链接:http://codeforces.com/problemset/problem/327/B 这道题目虽然超级简单,但是当初我还真的没有想出来做法,囧,看完别人的代码恍然大悟. #inclu ...
- 转:db2 backup 及 restore
db2 backup 及 restore 2011-06-21 18:12:20| 分类: AIX |举报 |字号 订阅 两个问题: db2=>list applications db ...
- spark新能优化之reduceBykey和groupBykey的使用
val counts = pairs.reduceByKey(_ + _) val counts = pairs.groupByKey().map(wordCounts => (wordCoun ...
- 越狱Season 1-Episode 17: J-Cat
Season 1, Episode 17: J-Cat -Pope: Hey, that's looking good. 嗨,看起来真棒 You're making some real progres ...