angularjs实战
1.指令 transclude 保留原来的内容 replace 去掉<my-directive>指令
- <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
- <div ng-app="a">
- <my-directive><div>这是原来的<p>this is p</p></div></my-directive>
- </div>
- <script>
- var app = angular.module('a', []);
- app.directive('myDirective', function () {
- return{
- template:'<div>this is directive<div ng-transclude=""></div></div>',
- transclude:true,
- replace:true
- }
- });
- </script>
2.指令绑定函数
- <body ng-app="a">
- <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
- <div ng-controller="ctrl1">
- <my-directive>鼠标移上来</my-directive>
- </div>
- <!--指令绑定函数 ,借助 link -->
- <script>
- var app = angular.module('a', []);
- app.controller('ctrl1', function ($scope) {
- $scope.load= function () {
- console.log("loading..");
- }
- })
- app.directive('myDirective', function () {
- return{
- link: function (scope,element,attrs) {
- element.bind('mouseover', function () {
- // scope.load();
- scope.$apply("load()"); // 两种方式
- })
- }
- }
- });
- </script>
3.指令复用,绑定不同函数
- <body ng-app="a">
- <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
- <div ng-controller="ctrl1">
- <my-directive howToLoad="load()">鼠标移上来1</my-directive>
- </div>
- <div ng-controller="ctrl2">
- <my-directive howToLoad="load2()">鼠标移上来2</my-directive>
- </div>
- <!--指令复用,绑定不同函数 ,要添加不同属性 howToLoad -->
- <script>
- var app = angular.module('a', []);
- app.controller('ctrl1', function ($scope) {
- $scope.load= function () {
- console.log("loading..");
- }
- })
- app.controller('ctrl2', function ($scope) {
- $scope.load2= function () {
- console.log("loading.22.");
- }
- })
- app.directive('myDirective', function () {
- return{
- link: function (scope,element,attrs) {
- element.bind('mouseover', function () {
- scope.$apply(attrs.howtoload);
- })
- }
- }
- });
- </script>
4.独立指令 $scope:{} 使每个复用的hello指令不受影响,在第一个hello输入值时,第二个hello不受影响
- <body ng-app="a">
- <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
- <hello></hello><br/>
- <hello></hello>
- <script>
- var app = angular.module('a', []);
- app.directive('hello', function () {
- return{
- template:'<input type="text" ng-model="name">{{name}}',
- scope:{}
- }
- })
- </script>
5.指令scope @
- <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
- 隔离作用域中把 myText同dom中的your-text属性绑定
- <div ng-app="a">
- <hello url="http://www.baidu.com" your-text="sohu"></hello>
- </div>
- <script>
- var app=angular.module('a',[]);
- app.directive('hello', function () {
- return{
- template:'<div><a href="{{url}}">{{myText}}</a></div>',
- replace:true,
- scope:{
- myText:'@yourText',
- url:'@'
- }
- }
- })
- </script>
angularjs实战的更多相关文章
- AngularJS实战之Controller之间的通信
我们时常会在不同controller之间进行通信,接下来就介绍三种controller之间的通信方式 一.使用$on.$emit和$broadcast进行controller通信 虽然AngularJ ...
- AngularJS实战项目(Ⅰ)--含源码
前言 钻研ABP框架的日子,遇到了很多新的知识,因为对自己而言是新知识,所以经常卡在很多地方,迟迟不能有所突破,作为一个稍有上进心的程序员,内心绝对是不服输的,也绝对是不畏困难的,心底必然有这样一股力 ...
- AngularJs学习笔记-慕课网AngularJS实战
第1章 快速上手 放弃了IE8以及以下,不支持. 4大核心特性: 1.MVC Model: 数据模型 View:视图 Controller:业务逻辑和控制逻辑 好处:职责清晰,模块化. 2.模块化 3 ...
- AngularJS 实战讲义笔记
第一部分 快速上手 1.1 感受AngularJs四大核心特性(MVC, 模块化,指令系统,双向数据绑定)1.2 搭建自动化的前端开发,调试,测试环境 代码编辑工具 (sublime) 断点调试工具 ...
- [置顶] AngularJS实战之路由ui-sref-active使用
当我们使用angularjs的路由时,时常会出现一个需求,当选中菜单时把当前菜单的样式设置为选中状态(多数就是改变颜色) 接下来就看看Angular-UI-Router里的指令ui-sref-acti ...
- 《AngularJs实战》学习笔记(慕课网)
1. Controller使用过程中的注意点 不要试图去复用Controller, 一个控制器一般只负责一小块视图 不要在Controller中操作DOM, 这不是控制器的职责. 封装在指令里. 不要 ...
- angularJS实战(一)
angular实现列表 accessCtrl.js let AccessCtrl = function($scope, AlertService, DialogService, BigDataServ ...
- AngularJS实战之cookie的读取
<!DOCTYPE html> <html ng-controller="cookies_controller"> <head> <tit ...
- AngularJS实战之ngAnimate插件实现轮播
第一步:引入angular-animate.js 第二步:注入ngAnimate var lxApp = angular.module("lxApp", [ 'ngAnimate' ...
随机推荐
- centos 本地dns配置
折腾了差不多两天,看了不少中文,英文文档.终于搞定,记录下心得.本文只讨论正向解析. 安装 ============= yum install bind 全局配置 ========= 由于只是做本地d ...
- NGUI图片闪光
先上效果 Shader Shader "Unlit/Transparent Colored Flow Texture" { Properties { _MainTex (" ...
- bind+dlz+mysql实现区域记录动态更新
BIND-DLZ实验:http://bind-dlz.sourceforge.net/ 实验环境:RHEL4,BIND-9.5.0-P2.tar.gz(9.4.0以上版本都已含DLZ补丁),Mysql ...
- SaltStack之Master配置文件详解
salt-master的配置文件位于/etc/salt/master,可用选项如下: #######################主配置 interface默认值:0.0.0.0(所有的网络地址接口 ...
- nyoj925_国王的烦恼_并查集
国王的烦恼 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 C国由n个小岛组成,为了方便小岛之间联络,C国在小岛间建立了m座大桥,每座大桥连接两座小岛.两个小岛间可能 ...
- Greedy:Bound Found(POJ 2566)
神奇密码 题目大意:就是给你一个数组,要你找出连续的数的绝对值的和最接近t的那一串,并且要找出数组的上界和下界的下标,并显示他们的和 因为这一题的数有正有负,所以必须要先把和求出来,然后排序,然 ...
- Spring mvc 文件上传到文件夹(转载+心得)
spring mvc(注解)上传文件的简单例子,这有几个需要注意的地方1.form的enctype=”multipart/form-data” 这个是上传文件必须的2.applicationConte ...
- nohup后台运行jar
nohup 用途:LINUX命令用法,不挂断地运行命令. 语法:nohup Command [ Arg ... ] [ & ] 描述:nohup 命令运行由 Command 参数和任何相关 ...
- 6. ZigZag Conversion
题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows l ...
- object实现小老鼠交互
直接使用 <p style="text-align: center; "> <object type="application/x-shockwave- ...