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. 内存映射mmap

    Table of Contents 1. 什么是mmap 2. 使用方法 2.1. mmap构造器的格式 2.2. 例子1 2.3. 例子2 3. 其它 4. 参考资料 什么是mmap 通常在Unix ...

  2. Spring MVC学习笔记02

    1.常用注解 1.@Autowired,它可以对类成员变量.方法及构造函数进行标注,完成自动装配的工作. <!-- 该 BeanPostProcessor 将自动起作用,对标注 @Autowir ...

  3. 100%会用到的angularjs的知识点【新手可mark】

    前言:下面我将整理出100%会到的angularjs的知识点,掌握这些知识点你基本上就可以独立完成一个angularjs的项目,前提是你有一定web开发的经验:1.了解基本的javascript的概念 ...

  4. 【阿里云产品公测】rds测试感受

    阿里云用户:cncbase 公司于10.1决定改变原来的服务器自建数据库,使用rds.于近日开通rds,进行了一些测试. 信息量:500字节左右每条信息,约200万条信息/小时的吞吐量.     信息 ...

  5. mysql的 join联合查询的通俗解释

    表a 1 2 3 4 aid adate 1 a1 2 a2 3 a3 表b 1 2 3 4 bid bdate 1 b1 2 b2 4 b4 两个表a.b相连接,要取出id相同的字段. 1 sele ...

  6. 水题2枚 Codevs1464&&Codevs1472

    1472 体检  时间限制: 1 s  空间限制: 64000 KB  题目等级 : 白银 Silver 题解  查看运行结果     题目描述 Description 郑厂长不是正厂长 也不是副厂长 ...

  7. @font-face 用字体画图标

    HTML <body> <!-- ul.layout>li*5>a[href=#]>i.icon --> <!-- Sublime Text 快捷拼写 ...

  8. 为IE单独写CSS的三种方法

    本文由 Kayo Lee 发表,本文链接:http://kayosite.com/the-methods-make-css-only-for-ie.html 因为万恶的 IE 存在各种的不标准,因此, ...

  9. 发布ASP.NET网站到IIS

    1.         在Web项目中点击发布网站,如图1所示 图1 2.         选择要发布的路径——>“确定”,如果项目显示发布成功就可以了.如图2所示 图2 3.         打 ...

  10. MVC4 图片上传

    新增 new { enctype = "multipart/form-data" } 这个必须要有 @using (Html.BeginForm(Html.BeginForm(&q ...