ionic 嵌套view 的方法

时间:2023-03-09 03:28:38
ionic 嵌套view  的方法

我一直想在一个页面的同一个 DIV 里面嵌入一个不同的 HTML文件  ....但是总是没有达到我要的效果.....才发现原来我没有加一个 name

我用angular-ui 插件 里面的样式  总是没有跳转....

     <div ui-view></div>
<!-- We'll also add some navigation: -->
<a ui-sref="state1">State 1</a>
<a ui-sref="state2">State 2</a>

在app.js 里面

 myApp.config(function($stateProvider, $urlRouterProvider) {
//
// For any unmatched url, redirect to /state1
$urlRouterProvider.otherwise("/state1");
//
// Now set up the states
$stateProvider
.state('state1', {
url: "/state1",
templateUrl: "partials/state1.html"
})
.state('state2', {
url: "/state2",
templateUrl: "partials/state2.html"
})
});

或者是这种方法

  <div ui-view="viewA"></div>
<div ui-view="viewB"></div>
<!-- Also a way to navigate -->
<a ui-sref="route1">Route 1</a>
<a ui-sref="route2">Route 2</a>

而在app.js 中

 myApp.config(function($stateProvider) {
$stateProvider
.state('index', {
url: "",
views: {
"viewA": { template: "index.viewA" },
"viewB": { template: "index.viewB" }
}
})
.state('route1', {
url: "/route1",
views: {
"viewA": { template: "route1.viewA" },
"viewB": { template: "route1.viewB" }
}
})

 });

我发现都没有达到我要的效果...

突然才发现我错了

ionic 比较是改过的...

我便这样做了

 <div ui-view name="myadd"></div>
 .state('tab.mytab1.router1',{
url:"/router1",
views: {
'myadd': {
templateUrl: 'addview.html',
}
}
})