Angular学习(7)- 模板
示例:
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<title>Study 7</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"}}
模板:<a href="javascript:void(0);" ng-repeat="t in templates">{{t}} </a><br />
</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, tpls) {
$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();
$scope.templates = tpls;
});
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 = '';
}
};
}
};
});
app.factory('tpls', function() {
return ['tpl1', 'tpl2', 'tpl3', 'tpl4'];
});
</script>
</body>
</html>
Angular学习(7)- 模板的更多相关文章
- angular学习笔记(三十)-指令(2)-restrice,replace,template
本篇主要讲解指令中的 restrict属性, replace属性, template属性 这三个属性 一. restrict: 字符串.定义指令在视图中的使用方式,一共有四种使用方式: 1. 元素: ...
- Angular 学习思路
近些年前端框架非常多,主流的有 Vue.React.Angular 等.我参与的项目中使用较多的是 Vue.因为 Vue 学习难度不大,上手很快,代码简洁,而且使用 Vue 全家桶(Vue + Vue ...
- Angular学习资料大全和常用语法汇总(让后端程序员轻松上手)
前言: 首先为什么要写这样的一篇文章呢?主要是因为前段时间写过一些关于Angualr的相关实战文章,有些爱学习的小伙伴对这方面比较感兴趣,但是又不知道该怎么入手(因为认识我的大多数小伙伴都是后端的同学 ...
- angular学习资源
angular学习资源 angularjs库: https://developers.google.com/speed/libraries/devguide?hl=zh-CN#angularjs ...
- angular学习-入门基础
angular .caret,.dropup>.btn>.caret{border-top-color:#000!important}.label{border:1px solid #00 ...
- angular学习—组件
组件: vue组件:xxx.vue react组件:xxx.js+xxx.css angular组件:xxx.ts+xxx.css+xxx.html angular的装饰器: @ngModule:an ...
- angular学习一框架结构认识
angular学习所有内容均会与vue以及react框架进行对比. angular学习使用的编译器:webstorm 解决编译器屏蔽node_modules包问题: File-->setting ...
- angular学习笔记(三十一)-$location(2)
之前已经介绍了$location服务的基本用法:angular学习笔记(三十一)-$location(1). 这篇是上一篇的进阶,介绍$location的配置,兼容各版本浏览器,等. *注意,这里介绍 ...
- angular学习笔记(三十一)-$location(1)
本篇介绍angular中的$location服务的基本用法,下一篇介绍它的复杂的用法. $location服务的主要作用是用于获取当前url以及改变当前的url,并且存入历史记录. 一. 获取url的 ...
- angular学习笔记(三十)-指令(10)-require和controller
本篇介绍指令的最后两个属性,require和controller 当一个指令需要和父元素指令进行通信的时候,它们就会用到这两个属性,什么意思还是要看栗子: html: <outer‐direct ...
随机推荐
- php中能够获取到某一网站内容的方法
方法一:file_get_contents 函数 example: <?php $url = "http://www.cnblogs.com"; $contents = fi ...
- spark streaming 实现接收网络传输数据进行WordCount功能
package iie.udps.example.operator.spark; import scala.Tuple2; import org.apache.spark.SparkConf; imp ...
- Python TF-IDF计算100份文档关键词权重
上一篇博文中,我们使用结巴分词对文档进行分词处理,但分词所得结果并不是每个词语都是有意义的(即该词对文档的内容贡献少),那么如何来判断词语对文档的重要度呢,这里介绍一种方法:TF-IDF. 一,TF- ...
- smartmontools的安装使用和实现对磁盘的Nagios监控
安装 首先从sourceforge下载最新的安装版本. 解压编译 $ tar -zxvf smartmontools-6.4.tar.gz $ cd smartmontools-6.4 $ ./con ...
- iOS学习笔记---c语言第十天
动态内存分配 一.存储区划分 从低到高(内存地址小----内存地址大) : 代码区---常量区---静态区---堆区---栈区 栈内存 //凡是在函数体内定义的变量 都存储在栈区(包括形参). ; ...
- Centos6下DRBD的安装配置
导读 Distributed Replicated Block Device(DRBD)是一个用软件实现的.无共享的.服务器之间镜像块设备内容的存储复制解决方案.数据镜像:实时.透明.同步(所有服务器 ...
- 关于SSH整合中对于Hibernate的Session关闭的问题
在web.xml的Struts2的配置上面加上 <filter> <filter-name>OpenSessionInViewFilter</filter-name> ...
- smartUpload组件单文件下载
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, ...
- hilbert矩阵
希尔伯特矩阵 希尔伯特矩阵是一种数学变换矩阵 Hilbert matrix,矩阵的一种,其元素A(i,j)=1/(i+j-1),i,j分别为其行标和列标. 即: [1,1/2,1/3,……,1/n] ...
- 某种数列问题 (jx.cpp/c/pas) 1000MS 256MB
众所周知,chenzeyu97有无数的妹子(阿掉!>_<),而且他还有很多恶趣味的问题,继上次纠结于一排妹子的排法以后,今天他有非(chi)常(bao)认(cheng)真(zhe)去研究一 ...