Route学习simple one

     ng的路由机制是靠ngRoute提供的,通过hashhistory两种方式实现了路由,可以检测浏览器是否支持history来灵活调用相应的方式。ng的路由(ngRoute)是一个单独的模块,包含以下内容:

  服务$routeProvider用来定义一个路由表,即地址栏与视图模板的映射.

  服务$routeParams保存了地址栏中的参数,例如{id : 1, name : 'tom'}.

  服务$route完成路由匹配,并且提供路由相关的属性访问及事件,如访问当前路由对应的controller.

  指令ngView用来在主视图中指定加载子视图的区域

  以上内容再加上$location服务,我们就可以实现一个单页面应用了。

   第一步:引入文件和依赖

   ngRoute模块包含在一个单独的文件中,所以第一步需要在页面上引入这个文件,如下:

<script src="http://code.angularjs.org/1.2.8/angular.min.js" rel="nofollow"/>

<script src="http://code.angularjs.org/1.2.8/angular-route.min.js" rel="nofollow"/>  

我们还需在模块声明中注入对ngRoute的依赖,如下:

var app = angular.module('MyApp', ['ngRoute']);  

   第二步:定义路由表

  $routeProvider提供了定义路由表的服务,它有两个核心方法,when(path,route)otherwise(params),先看一下核心中的核心when(path,route)方法。

  when(path,route)方法接收两个参数,path是一个string类型,表示该条路由规则所匹配的路径,它将与地址栏的内容($location.path)值进行匹配。如果需要匹配参数,可以在path中使用冒号加名称的方式,如:path/show/:name,如果地址栏是/show/tom,那么参数name和所对应的值tom便会被保存在$routeParams中,像这样:{name : tom}。我们也可以用*进行模糊匹配,如:/show*/:name将匹配/showInfo/tom

  route参数是一个object,用来指定当path匹配后所需的一系列配置项,包括以下内容:

    controller //functionstring类型。在当前模板上执行的controller函数,生成新的scope

   controllerAs //string类型,为controller指定别名;

   template //stringfunction类型,视图z所用的模板,这部分内容将被ngView引用;

   templateUrl //stringfunction类型,当视图模板为单独的html文件或是使用了<script type="text/ng-template">定义模板时使用;

   resolve //指定当前controller所依赖的其他模块;

   redirectTo //重定向的地址。

最简单情况,我们定义一个html文件为模板,并初始化一个指定的controller

function emailRouteConfig($routeProvider){

      $routeProvider.

when('/show', {

         controller: ShowController,

         templateUrl: 'show.html'

     }).

when('/put/:name',{

        controller: PutController,

        templateUrl: 'put.html'

     });  

};  

otherwise(params)方法对应路径匹配不到时的情况,这时候我们可以配置一个redirectTo参数,让它重定向到404页面或者是首页。

   第三步:在主视图模板中指定加载子视图的位置

  我们的单页面程序都是局部刷新的,那这个“局部”是哪里呢,这就轮到ngView出马了,只需在模板中简单的使用此指令,在哪里用,哪里就是“局部”。例如:

<div ng-view></div>  或:<ng-view></ng-view>  

代码简单如下:

var app = angular.module("personApp", ['ngRoute']);
app.config(['$routeProvider',function ($routeProvider) {
        $routeProvider
        .when('/:tid', {
            templateUrl: 'person-route.html',
            controllerAS: 'personInfoCon'
        })
        .otherwise({
            templateUrl: 'person-route.html',
            controllerAs: 'personInfoCon'
        });
}]);
app.controller("personInfoCon", function($scope, $routeParams, PersonService, AboutTopicService, CommentService){
    $scope.tid = "127";
    $scope.page = "1";
    $scope.pagesArray = [];

    if($routeParams.tid) {
        $scope.tid = $routeParams.tid;
    }
    ......
}
<div class="aboutperson-block" ng-repeat="person in persons">
    <a href="#/{{person.teacherId}}">
        <img class="aboutperson-block-img"ng-src="{{person.url}}">
        <label class="aboutperson-block-name">{{person.name}}</label>
        <label class="aboutperson-block-topic">{{person.topic}}</label>
        <label class="aboutperson-block-simpleinfo">{{person.simpleInfo}} CEO</label>
        <label class="aboutperson-block-likeno"><img src="http://image.1yingli.cn/img/kelly.png"><span>{{person.likenumber}}人想见</span></label>
    </a>
</div>
或者:

demoApp.config(['$routeProvider',function($routeProvider) {  

$routeProvider.when('/list', {  

templateUrl: 'route/list.html',  

  controller: 'routeListController'

}).when('/list/:id', {  

  templateUrl: 'route/detail.html',

   controller: 'routeDetailController'

  }).otherwise({  

        redirectTo: '/list'  

     });  

}]);

controller注意事项: 

controller 和controllerAs的区别,页面加载获取数据会加载两次。

ng-controller的初始化位置,页面初始化开始加载ng-controller,所有要避免无用的http请求。

https://github.com/johnpapa/angular-styleguide/blob/master/i18n/zh-CN.md#
http://www.lovelucy.info/angularjs-best-practices.html
https://code.angularjs.org/1.4.7/docs/api



1、Digital circuits are made from large assemblies of logic gates, which gate cell is the most simple one(5 分) AINV BNAND CNOR DDFF 2、以下逻辑功能符号错误的是(5 分) A与:& B或:| C非:^ D异或:^ 3、关于后端数字设计流程的描述错误的是(5 分) APhysical Verification主要包含DRC、LVS检查等 BPost-layout Verification是用Place&Route产生的网表做晶体管级仿真 CSTA Timing是对布局布线后的结果做时序分析 DPlace&Route 是对综合后的门级网表做布局布线的进一步处理 4、关于前端数字设计流程迭代过程的描述错误的是(5 分) A如果RTL Verification有错误,需要返回到RTL design并再次Verification B如果Logic Synthesis结果有violation,需要迭代几次Synthesis或者返回RTL Design C如果Gate-level Verification有错误,可能返回Logic Synthesis D如果Gate-level Verification有错误,不会返回到RTL Design 5、关于后端数字设计流程迭代过程的描述错误的是(5 分) A如果Place&Route结果有violation,可以尝试多次迭代 B如果STA Timing结果有violation,可以尝试多次迭代 C如果Post-layout Verification有错误,可能需要返回Place&Route D如果Place&Route结果无误,则进入STA Timing流程 6、以下硬件描述形式,是门级描述常用的方法的是(5 分) Aalways块 Bif条件语句 Cassign赋值语句 D模块例化 7、A classical verification testbench structure does not include(5 分) ADUT BStimulus CMonitors DScoreboard 8、Following testbench components will collect the simulation result except(5 分) AChecker BStimulus CMonitors DScoreboard 9、The description of testbench components are correct except(5 分) AMonitor: capture output/status BChecker: compare input with output and status to analysis whether DUT function pass CReference Model: golden models of some functional blocks for verification DScoreboard: store some key flags to control the stimulus 10、Following UVM components are under uvm_agent except(5 分) Auvm_monitor Buvm_driver Cuvm_cofig Duvm_sequencer 11、Following descriptions of NCsim commands are correct except(5 分) Ancverilog: Compiles the Verilog source files Bncvlog: Compiles the Verilog source files Cncelab: Elaborates the design and generates a simulation snapshot Dncsim: Simulates the snapshot 12、The input files of Logic Synthesis do not include(5 分) AVerilog file of RTL design BConstraint file CStandard delay file DTiming library file 13、Logic Synthesis flow does not include(5 分) ASetting Design Environment BSetting Design Constraint CCompile Design DSpecification 14、The wrong description of physical aware Synthesis is(5 分) ADCG has more physical library and layer, congestion related setting BDCG can more accurately consider the path median delay, and optimize the timing with more accurate path CDCG usually extracts physical constraint information from DEF files after ICC is floorplan DDCG use “dc_shell –dcg” to launch 15、The Place&Route includes following activities except(5 分) AFunctionality check BDesign Preparation CDesign Planning DPlacement 16、Following steps are included in Place&Route except(5 分) AClock Tree Synthesis BRoute CFormal equivalence check DChip Finishing 17、The input files of Static Timing Analysis do not include(5 分) ADesign data BGDS file CParasitic data file DTiming library file 18、Analysis modes of STA do not include(5 分) ASingle mode BBC_WC mode CPPA mode DOCV mode 19、The elements to construct different scenarios in MCMM do not include(5 分) ADifferent clock tree methods BPVT corners CDifferent functional modes with different constraint DParasitic views 20、The wrong description of post-layout verification is(5分) AUse post-layout netlist from APR tool as one of inputs BUse SDF file generated by STA tool to annotate timing delay info CCan use parasitic file SPEF for timing delay calculation DUse “–sdf” option to active SDF file in simulation
09-20
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值