<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link href="https://cdn.bootcss.com/ionic/1.3.2/css/ionic.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/ionic/1.3.2/js/ionic.bundle.min.js"></script>
<title>ionic实现页面切换</title>
<!-- 点击按钮时调取相应的html文件 -->
<script type="text/javascript">
var app = angular.module("myApp", ["ionic"]);
app.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider.state("home", {
url: "/home",
views: {
"views_home": {
templateUrl: "home.html"
}
}
}).state("cart", {
url: "/cart",
views: {
"views-cart": {
templateUrl: "cart.html"
}
}
}).state("mine", {
url: "/mine",
views: {
"views-mine": {
templateUrl: "mine.html"
}
}
})
});
</script>
</head>
<body>
<!-- 搭建主页面框架 -->
<ion-tabs class="tabs-positive tabs-icon-top">
<ion-tab title="首页" icon-on="ion-ios-filing" icon-off="ion-ios-filing-outline" ui-sref="home">
<ion-nav-view name="views_home"></ion-nav-view>
</ion-tab>
<ion-tab title="购物车" icon-on="ion-ios-cart" icon-off="ion-ios-cart-outline" ui-sref="cart">
<ion-nav-view name="views-cart"></ion-nav-view>
</ion-tab>
<ion-tab title="我的" icon-on="ion-ios-person" icon-off="ion-ios-person-outline" ui-sref="mine">
<ion-nav-view name="views-mine"></ion-nav-view>
</ion-tab>
</ion-tabs>
<!-- 点击按钮后,将相应的页面元素加入到框架页面中 -->
<script id="home.html" type="text/ng-template">
<ion-header-bar class="bar-positive">
<button class="button button-clear">左按钮</button>
<h1 class="title">首页</h1>
</ion-header-bar>
<ion-content class="has-header">
这是“首页”页面HTML内容
</ion-content>
</script>
<script id="cart.html" type="text/ng-template">
<ion-header-bar class="bar-positive">
<h1 class="title">购物车</h1>
<button class="button button-clear">右按钮</button>
</ion-header-bar>
<ion-content class="has-header">
这是“购物车”页面HTML内容
</ion-content>
</script>
<script id="mine.html" type="text/ng-template">
<ion-header-bar class="bar-positive">
<h1 class="title">我的</h1>
<button class="button button-icon ion-ios-more"></button>
</ion-header-bar>
<ion-content class="has-header">
这是“我的”页面HTML内容
</ion-content>
</script>
</body>
</html>
ionic练习(1)- 实现页面切换
最新推荐文章于 2018-05-26 09:12:41 发布