博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AngularJS $route
阅读量:4444 次
发布时间:2019-06-07

本文共 2279 字,大约阅读时间需要 7 分钟。

暂时只是知道怎样用,还没理解,就先展示怎样的流程,待日后再来表明理解

结构

先看下Index.html

                    

需要注意的点是:1 需要添加angular-route.js这个js插件

          2 添加 ng-view

再看看list.html和detail.html的模板内容

Subject: {
{message.subject}}
Sender: {
{message.sender}}
Date: {
{message.date}}
To:
{
{recipient}}
{
{message.message}}
Back to message list
Search:
Sort by:

重点看下app.js这个js的内容

angular.module("news", ['ngRoute']).    config(['$routeProvider', function ($routeProvider) {        $routeProvider.        when('/', { templateUrl: 'partials/list.html', controller: newsListController }).        when('/news/:newsId', { templateUrl: 'partials/detail.html', controller: newsDetailController }).        otherwise({redirectTo:'/'});    } ]);

注意点:1 添加ngRoute

    2 熟悉拼写的格式

 

controller.js

// 一些虚拟的邮件 messages = [{   id: 0, sender: 'jean@somecompany.com', subject: 'Hi there, old friend',   date: 'Dec 7, 2013 12:32:00', recipients: ['greg@somecompany.com'],   message: 'Hey, we should get together for lunch sometime and catch up.There are many things we should collaborate on this year.' }, {   id: 1,  sender: 'maria@somecompany.com',   subject: 'Where did you leave my laptop?',   date: 'Dec 7, 2013 8:15:12', recipients: ['greg@somecompany.com'],   message: 'I thought you were going to put it in my desk drawer.But it does not seem to be there.' }, {   id: 2, sender: 'bill@somecompany.com', subject: 'Lost python',   date: 'Dec 6, 2013 20:35:02', recipients: ['greg@somecompany.com'],   message: "Nobody panic, but my pet python is missing from her cage.She doesn't move too fast, so just call me if you see her." }]; // 把我们的邮件发布给邮件列表模板function newsListController($scope) {    $scope.phones = messages; } // 从路由信息(从URL 中解析出来的)中获取邮件id,然后用它找到正确的邮件对象 function newsDetailController($scope, $routeParams) {     $scope.message = messages[$routeParams.id]; }

 

转载于:https://www.cnblogs.com/lihaozhou/p/3665225.html

你可能感兴趣的文章
Hibernate原理解析-Hibernate中实体的状态
查看>>
六时车主 App 隐私政策
查看>>
C语言常见问题 如何用Visual Studio编写C语言程序测试
查看>>
Web用户的身份验证及WebApi权限验证流程的设计和实现
查看>>
hdu 2098 分拆素数和
查看>>
[ONTAK2010]Peaks kruskal重构树,主席树
查看>>
ECMAScript6-let与const命令详解
查看>>
iOS 使用系统相机、相册显示中文
查看>>
什么是敏捷设计
查看>>
SCSS的基本操作
查看>>
"安装程序无法定位现有系统分区" 问题解决
查看>>
.NET中栈和堆的比较
查看>>
【莫队】bzoj 3781,bzoj 2038,bzoj 3289
查看>>
如何优化limit
查看>>
几种常用数据库字段类型查询语句
查看>>
字符全排列
查看>>
提高效率必须改掉的7种习惯
查看>>
Java判断语句中判断条件的执行顺序
查看>>
Windows平台下tomcat+java的web程序持续占cpu问题调试
查看>>
OO第四次博客作业!
查看>>