首页 技术 正文
技术 2022年11月15日
0 收藏 337 点赞 4,489 浏览 3383 个字

接着之前的ionic的例子 查看例子:我的第一段ionic代码

demo3.html(黄底内容为增加或修改的内容)

<!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="utf-8">
<title>ionic-demo3</title>
<link href="../lib/ionic/css/ionic.css" rel="external nofollow" rel="external nofollow" rel="stylesheet">
<script type="text/javascript" src="../lib/ionic/js/ionic.bundle.js" charset="utf-8"></script>
</head>
<body>
<ion-nav-bar class="bar-stable"></ion-nav-bar>
<ion-nav-view></ion-nav-view>
<script type="text/javascript">
var app = angular.module('app',['ionic']); app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('menu', {
url: '/menu',
templateUrl: 'menu.html',
abstract: true,
controller: 'MenuCtrl'
})
.state('menu.dash', {
url: '/dash',
views:{
'menuContent':{
templateUrl: 'dash.html',
controller: 'DashCtrl'
}
}
}); $urlRouterProvider.otherwise('/menu/dash'); }); app.controller('MenuCtrl', function($scope) {});
app.controller('DashCtrl', function($scope) {});
</script>
</body>
</html>

menu.html(该页面为新增页面)

 <ion-side-menus>      <ion-pane ion-side-menu-content>
<ion-nav-bar class="bar-stable nav-title-slide-ios7">
<ion-nav-back-button class="button-clear"><i class="icon ion-chevron-left"></i> Back</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>
</ion-pane> <ion-side-menu side="left">
<header class="bar bar-header bar-stable">
<h1 class="title">Left</h1>
</header>
<ion-content class="has-header">
<ion-list>
<ion-item nav-clear menu-close href="#/app/search" rel="external nofollow" >
Search
</ion-item>
<ion-item nav-clear menu-close href="#/app/browse" rel="external nofollow" >
Browse
</ion-item>
<ion-item nav-clear menu-close href="#/app/playlists" rel="external nofollow" >
Playlists
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>

dash.html(黄底内容为增加或修改的内容)

<ion-view view-title="Dashboard">      <ion-nav-buttons side="left">
<button menu-toggle="left" class="button button-icon icon ion-navicon"></button>
</ion-nav-buttons> <ion-content class="padding">
<div class="list card">
<div class="item item-divider">Recent Updates</div>
<div class="item item-body">
<div>
There is a fire in <b>sector 3</b>
</div>
</div>
</div>
<div class="list card">
<div class="item item-divider">Health</div>
<div class="item item-body">
<div>
You ate an apple today!
</div>
</div>
</div>
<div class="list card">
<div class="item item-divider">Upcoming</div>
<div class="item item-body">
<div>
You have <b>29</b> meetings on your calendar tomorrow.
</div>
</div>
</div>
</ion-content>
</ion-view>

写到这里,出现一个问题,就是菜单和内容是两个页面,如果在菜单页中需要执行内容页的内容的话,要怎么执行呢?

我这里使用了广播的方法,把上面的代码继续改造:

demo3.html(黄底内容为增加或修改的内容)

<!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="utf-8">
<title>ionic-demo3</title>
<link href="../lib/ionic/css/ionic.css" rel="external nofollow" rel="external nofollow" rel="stylesheet">
<script type="text/javascript" src="../lib/ionic/js/ionic.bundle.js" charset="utf-8"></script>
</head>
<body>
<ion-nav-bar class="bar-stable"></ion-nav-bar>
<ion-nav-view></ion-nav-view>
<script type="text/javascript">
var app = angular.module('app',['ionic']); app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('menu', {
url: '/menu',
templateUrl: 'menu.html',
abstract: true,
controller: 'menuCtrl'
})
.state('menu.dash', {
url: '/dash',
views:{
'menuContent':{
templateUrl: 'dash.html',
controller: 'DashCtrl'
}
}
}); $urlRouterProvider.otherwise('/menu/dash'); }); app.controller('menuCtrl', function($scope) {
$scope.func = function(text) {
$scope.$broadcast("func", text);
}
});
app.controller('DashCtrl', function($scope) {
$scope.msg = "测试内容"; $scope.$on("func",function (event, text) {
alert("本页内容:" + $scope.msg + "\n传过来内容:" + text);
});
});
</script>
</body>
</html>

menu.html和dash.html页面不变

发送广播,使用$scope.$broadcast

接收广播,使用$scope.$on

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,945
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,471
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,284
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,100
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,732
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,767