angular定义一个模块(module)及控制器(controller)的局部声明方法:

var app=angular.module("Myapp",[]);
myapp.controller("myctrl",['$scope','$window',function($scope,$window){
    $scope.name="欢迎来到 Angular 的世界!";
    $scope.value="100";
    //$window.alert(8)
}])

var app=angular.module("Myapp",[]);

1、红色字的 Myapp是在页面中ng-app="Myapp"调用的(一个页面中只能出现一次<html ng-app="Myapp">表示这个页面从此处开始,里面的东西都将由angular来管理)

2、[] 这个是我们要调用另外一个模块时,导入模块的地方,如果没用到其它模块,这里则为空

示例如下:Myapp

var bookStoreApp = angular.module('bookStoreApp', [
    'ngRoute', 'ngAnimate', 'bookStoreCtrls', 'bookStoreFilters',
    'bookStoreServices', 'bookStoreDirectives','Myapp'
]);

3、$scope,$window 表示向控制器中注入这两个参数,并依赖这两个变量;

 myapp.controller("myctrl",['$scope','$window',function($scope,$window){

}])

Angular 使用参数详解>>.

UIRoute1.html 项目引导的首页面

<!doctype html>
<html ng-app="MyUIRoute">

<head>
    <meta charset="utf-8">
    <script src="js/angular-1.3.0.js"></script>
    <script src="js/angular-animate.js"></script>
    <script src="js/angular-ui-router.js"></script>
    <script src="UIRoute1.js"></script>
</head>

<body>
    <div ui-view></div>
    <a ui-sref="state1">State 1</a>
    <a ui-sref="state2">State 2</a>
</body>

</html>
var myUIRoute = angular.module('MyUIRoute', ['ui.router', 'ngAnimate']);
myUIRoute.config(function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise("/state1");//此处设置默认打开页路径
    $stateProvider
        .state('state1', {//此处'state1'为打开的这个默认页面state1.html的页面名称,
		                  //方便通过a标签<a ui-sref="state1.list">Show List</a>访问子页面
            url: "/state1",//此处为设置的页面访问路径与$urlRouterProvider.otherwise("/state1")默认打开页路径对应
			               //即在浏览器中输入#/state1则打开state1.html页面,此为默认打开页,所以一进来就自动加了#/state1
            templateUrl: "tpls/state1.html"
        })
        .state('state1.list', {//当通过父页面state1点击a标签<a ui-sref="state1.list">Show List</a>访问子页面时,
		                      //此处即为设置a标签访问的页面名称
            url: "/list",//此处为设置的页面访问路径(父级必须存在,才能有效,要不然在地址栏加#/list会无效)
            templateUrl: "tpls/state1.list.html",
            controller: function($scope) {//此处为设置state1.list.html页面受控哪个控制器
                $scope.items = ["A", "List", "Of", "Items"];
            }
        })
        .state('state2', {//此处'state2'为打开的这个页面state2.html的页面名称,
		                  //方便通过a标签<a ui-sref="state2">State 2</a>访问页面
            url: "/state2",//此处为设置的页面访问路径,切换到这个页面时,
			               //会自动在地址栏添加,不写则不会有,也可以开页面但是,没办法保存访问地址
            templateUrl: "tpls/state2.html"
        })
        .state('state2.list', {
            url: "/list",
            templateUrl: "tpls/state2.list.html",
            controller: function($scope) {
                $scope.things = ["A", "Set", "Of", "Things"];
            }
        });
});

 
注意点
1、打开页面时如果没在js中设置views视图,则默认在点击的那个页面中的匿名view(如:ui-view)中打开,如果不是,则要设置views中的视图名称,如果要替换当前页,则直接用本页打开时采用的视图名

2、在哪个页面中打开的页面,a标签中的路径一定要写到完整,从最父级写到本页 ,
    如:<a ui-sref="index.usermng.highendusers" class="list-group-item">高端用户</a>
   因为在app.js中与state中的参数,对应

  $stateProvider.state('index.usermng.highendusers', {
            url: '/highendusers',
            templateUrl: 'tpls3/highendusers.html'
        })

3、ui-router中关于内嵌ui-view

首先有个启动页

<!doctype html>
<html ng-app="routerApp">

<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/bootstrap-3.0.0/css/bootstrap.css">
    <link rel="stylesheet" href="css/index.css">
    <script src="js/angular-1.3.0.js"></script>
    <script src="js/angular-animate.js"></script>
    <script src="js/angular-ui-router.js"></script>
    <script src="UIRoute3.js"></script>
</head>

<body>
    <div ui-view></div>
</body>

</html>

假如在启动页面中的一级子页面index.html中有二级ui-view,

<div class="container">
        <div ui-view="topbar"></div>
        <div ui-view="main"></div>
     </div>

则可通过@符号来衔接:
  比如一级子页面index.html,state第一个路由命名参数命名为index,
  则其本身中放的视图ui-view要用本身子页面的视图名称@自身页面被命名的路由名称
  如下图代码

var routerApp = angular.module('routerApp', ['ui.router']);
routerApp.config(function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/index');
    $stateProvider
        .state('index', {
            url: '/index',
            views: {
                '': {
                    templateUrl: 'tpls3/index.html'
                },
                'topbar@index': {
                    templateUrl: 'tpls3/topbar.html'
                },
                'main@index': {
                    templateUrl: 'tpls3/home.html'
                }
            }
        })
        .state('index.usermng', {
            url: '/usermng',
            views: {
                'main@index': {
                    templateUrl: 'tpls3/usermng.html',
                    controller: function($scope, $state) {
                        $scope.addUserType = function() {
                            $state.go("index.usermng.addusertype");
                        }
                    }
                }
            }
        })
        .state('index.usermng.highendusers', {
            url: '/highendusers',
            templateUrl: 'tpls3/highendusers.html'
        })
        .state('index.usermng.normalusers', {
            url: '/normalusers',
            templateUrl: 'tpls3/normalusers.html'
        })
        .state('index.usermng.lowusers', {
            url: '/lowusers',
            templateUrl: 'tpls3/lowusers.html'
        })
        .state('index.usermng.addusertype', {
            url: '/addusertype',
            templateUrl: 'tpls3/addusertypeform.html',
            controller: function($scope, $state) {
                $scope.backToPrevious = function() {
                    window.history.back();
                }
            }
        })
        .state('index.permission', {
            url: '/permission',
            views: {
                'main@index': {
                    template: '这里是权限管理'
                }
            }
        })
        .state('index.report', {
            url: '/report',
            views: {
                'main@index': {
                    template: '这里是报表管理'
                }
            }
        })
        .state('index.settings', {
            url: '/settings',
            views: {
                'main@index': {
                    template: '这里是系统设置'
                }
            }
        })
});

angular指令>>>>.

var appModule=angular.module('AppModule',[]);appModule.directive('hello',function(){
return {
restrict:'EACM',
template:'<div>88</div>',
replace:true
}
})
1、restrict匹配模式

restrict:'EACM',  4个参数含义:

E:元素方式
     <hello>这是测试angular.js指令标签的内容</hello>

A:属性方式
     <div hello>这是测试angular.js指令标签的内容</div>

C:样式类方式
     <div class="hello">这是测试angular.js指令标签的内容</div>

M:注释方式,此处directive:hellow左右必须要加空格才行

<!-- directive:hellow -->
   <div>这是测试angular.js指令标签的内容</div>

2、templateUrl替换template解决引入大量html结构代码及页面问题;



注意点:被引入的页面,如下:hello.html页面代码中一定要有一个包裹所有代码的父级元素,angular在插入到相应指令代码中时,会把这个父级div的所有属性,(如class id 及其他的属性),给组合到指令代码<hello></hello>的这个标签中;
   <div id="banner">
      <div id="focus" class="focus" hello >

      </div>
   </div>
var directive=angular.module('mydirective',[]);
directive.directive('hello',function(){
    return {
        restrict:"AE",
        templateUrl: 'banner.html',
        replace:true,
        link:function(scope,element,attrs){
            console.log(element);
            console.log(scope);
            console.log(attrs);
        }
    }
})

要被插入的 hello.html 页面代码

<div>      //这为包裹所有元素的父级div
    <div class="bd">
        <ul>
            <li>
                <a href="javascript:void(0);"><img src="data:images/640-350.jpg" /></a>
            </li>
            <li>
                <a href="javascript:void(0);"><img src="data:images/640-350.jpg" /></a>
            </li>
            <li>
                <a href="javascript:void(0);"><img src="data:images/640-350.jpg" /></a>
            </li>
            <li>
                <a href="javascript:void(0);"><img src="data:images/640-350.jpg" /></a>
            </li>
        </ul>
    </div>
    <div class="hd">
        <ul id="hd-ul"></ul>
    </div>
</div>

  

3、angular内置方法$templateCache实现模版缓存共用
var myModule = angular.module("MyModule", []);

//注射器加载完所有模块时,run方法会执行一次
myModule.run(function($templateCache){
	$templateCache.put("key_name","<div>Hello everyone!!!!!!</div>");//$templateCache.put把右边的模版内容缓存起来
});

myModule.directive("hello", function($templateCache) {
    return {
        restrict: 'AECM',
        template: $templateCache.get("key_name"),//通过$templateCache.get调用$templateCache缓存的模版
        replace: true
    }
});

$templateCache.put('key_name','html结构') 中的参数,就相当于key value 的概念吧,第一部分是名称,第二部分写内容,要用到的时候写名称就行 
$templateCache.get('key_name')
 

4.transclude实现指令中template的HTML结构嵌套(嵌套内容为,设置的指令元素中,页面预留的html结构)

<!doctype html>
<html ng-app="MyModule">
	<head>
		<meta charset="utf-8">
	</head>
	<body>
		<hello>
			<div>这里是指令内部的内容。</div>
			<div>这里是指令内部的内容。</div>
			<div>这里是指令内部的内容。</div>
		</hello>
	</body>
	<script src="framework/angular-1.3.0.14/angular.js"></script>
	<script src="transclude.js"></script>
</html>

  

var myModule = angular.module("MyModule", []);
myModule.directive("hello", function() {
    return {
    	restrict:"AE",
    	transclude:true,
    	template:"<div>Hello everyone!<div ng-transclude></div>omo</div>"
    }
});

效果图如下,
  



angular这个大梗的学习笔记的更多相关文章

  1. 大数据 -- kafka学习笔记:知识点整理(部分转载)

    一 为什么需要消息系统 1.解耦 允许你独立的扩展或修改两边的处理过程,只要确保它们遵守同样的接口约束. 2.冗余 消息队列把数据进行持久化直到它们已经被完全处理,通过这一方式规避了数据丢失风险.许多 ...

  2. Angular.js之自定义指令学习笔记

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  3. Angular.js之内置过滤器学习笔记

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. Pollard Rho大质数分解学习笔记

    目录 问题 流程 代码 生日悖论 end 问题 给定n,要求对n质因数分解 普通的试除法已经不能应用于大整数了,我们需要更快的算法 流程 大概就是找出\(n=c*d\) 如果\(c\)是素数,结束,不 ...

  5. Angular 学习笔记 ( CDK - Accessibility )

    @angular/ckd 是 ng 对于 ui 组建的基础架构. 是由 material 团队开发与维护的, 之所以会有 cdk 看样子是因为在开发 material 的时候随便抽象一个层次出来给大家 ...

  6. Angular 5.x 学习笔记(1) - 模板语法

    Angular 5.x Template Syntax Learn Note Angular 5.x 模板语法学习笔记 标签(空格分隔): Angular Note on github.com 上手 ...

  7. Hadoop学习笔记一

    云帆大数据视频学习笔记,记录如下. 一.主机名设置的规范 /etc/hosts文件中添加如下的记录: 192.168.1.128 hadoop-yarn.cloudyhadoop.com had-ya ...

  8. 不错的Spring学习笔记(转)

    Spring学习笔记(1)----简单的实例 ---------------------------------   首先需要准备Spring包,可从官方网站上下载.   下载解压后,必须的两个包是s ...

  9. Spring学习笔记(七)模拟实际开发过程的调用过程XML版-Setter方式注入

    模拟实际开发过程的调用过程XML版-Setter方式注入 源码获取github [TOC] 1.项目结构 2.jar包跟上个一样 3.重写set方法 UserServiceImpl.java 1234 ...

随机推荐

  1. A*算法解决八数码问题 Java语言实现

    0X00 定义 首先要明确一下什么是A*算法和八数码问题? A*(A-Star)算法是一种静态路网中求解最短路径最有效的直接搜索方法也是一种启发性的算法,也是解决许多搜索问题的有效算法.算法中的距离估 ...

  2. Sql 之 sql中的强制类型转换

    1. convert(数据类型, 字段名) convert(datetime, startDate) 2. cast(字段名 as 数据类型) ,))

  3. myecplise 打开报错 Errors occurred during the build. Errors running builder 'DeploymentBuilder' on project 'myf'. Java.lang.NullPointerException

    Errors occurred during the build. Errors running builder 'DeploymentBuilder' on project 'myf'.Java.l ...

  4. python使用rrdtool时 argument 0 must be string的问题

    在updatev rrdfile时, ret = rrdtool.updatev(filename, ds) 报了argument 0 must be string的异常,经查是因为python 的r ...

  5. 【Android 界面效果14】RelativeLayout里常用的位置属性

    ------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- android:layout_toLeftOf—— 该组件位于引用组件的左方 android:layou ...

  6. mina 字节数组编解码器的写法 II

    I 里面的写法不够严谨,这也是我之前说它简陋的主要原因,下面来个更加严谨.完整一点儿的: ByteArrayEncoder.java package org.bruce.mina.cpp.codec; ...

  7. 《MFC游戏开发》笔记十 游戏中的碰撞检测进阶:地图类型&障碍物判定

    本系列文章由七十一雾央编写,转载请注明出处. http://blog.csdn.net/u011371356/article/details/9394465 作者:七十一雾央 新浪微博:http:// ...

  8. POJ 2031 Building a Space Station (最小生成树)

    Building a Space Station Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5173   Accepte ...

  9. jQuery选择器之表单对象属性过滤选择器Demo

    测试代码: 08-表单对象属性过滤选择器.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  10. hdu 4705 排列组合

    思路:枚举能是A,B,C在一条简单路径上的中点. 计算多少个几何能满足.在用总数减去 #pragma comment(linker, "/STACK:16777216") #inc ...