无法从状态 '' 解析 '...' [英] Could not resolve '...' from state ''
问题描述
这是我第一次尝试使用 ui-router.
This is first time i am trying to use ui-router.
这是我的 app.js
Here is my app.js
angular.module('myApp', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise("/index.html");
$stateProvider.state('index', {
url: '/'
template: "index.html",
controller: 'loginCtrl'
});
$stateProvider.state('register', {
url: "/register"
template: "register.html",
controller: 'registerCtrl'
});
})
如您所见,我有两种状态.我正在尝试像这样注册状态:
As you can see, i have two states. I'm trying to register state like this:
<a ui-sref="register">
<button class="button button-balanced">
Create an account
</button>
</a>
但我得到了
无法从状态"解析注册"
Could not resolve 'register' from state ''
异常.这里有什么问题?
exception. What is the problem here?
推荐答案
这种错误通常表示(JS)代码的某些部分没有加载.ui-sref
内部的状态丢失.
This kind of error usually means that some parts of (JS) code were not loaded. That the state which is inside of ui-sref
is missing.
我不是 ionic 方面的专家,所以这个例子应该表明它可以工作,但我使用了更多技巧(标签的父级)
这是一个有点调整的状态def:
This is a bit adjusted state def:
.config(function($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise("/index.html");
$stateProvider
.state('app', {
abstract: true,
templateUrl: "tpl.menu.html",
})
$stateProvider.state('index', {
url: '/',
templateUrl: "tpl.index.html",
parent: "app",
});
$stateProvider.state('register', {
url: "/register",
templateUrl: "tpl.register.html",
parent: "app",
});
$urlRouterProvider.otherwise('/');
})
这里我们有带有标签的父视图及其内容:
And here we have the parent view with tabs, and their content:
<ion-tabs class="tabs-icon-top">
<ion-tab title="Index" icon="icon ion-home" ui-sref="index">
<ion-nav-view name=""></ion-nav-view>
</ion-tab>
<ion-tab title="Register" icon="icon ion-person" ui-sref="register">
<ion-nav-view name=""></ion-nav-view>
</ion-tab>
</ion-tabs>
不仅仅是一个如何让它运行的例子,然后以正确的方式使用离子框架......检查那个例子 这里
这里有类似的问答一个使用命名视图的示例(肯定更好的解决方案) 离子路由问题,显示空白页面一个>
Here is similar Q & A with an example using the named views (for sure better solution) ionic routing issue, shows blank page
标签中带有命名视图的改进版本在这里:http://plnkr.co/编辑/Mj0rUxjLOXhHIelt249K?p=preview
Improved version with named views in a tab is here: http://plnkr.co/edit/Mj0rUxjLOXhHIelt249K?p=preview
<ion-tab title="Index" icon="icon ion-home" ui-sref="index">
<ion-nav-view name="index"></ion-nav-view>
</ion-tab>
<ion-tab title="Register" icon="icon ion-person" ui-sref="register">
<ion-nav-view name="register"></ion-nav-view>
</ion-tab>
定位命名视图:
$stateProvider.state('index', {
url: '/',
views: { "index" : { templateUrl: "tpl.index.html" } },
parent: "app",
});
$stateProvider.state('register', {
url: "/register",
views: { "register" : { templateUrl: "tpl.register.html", } },
parent: "app",
});
这篇关于无法从状态 '' 解析 '...'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!