无法解析'...'从国家' [英] Could not resolve '...' from state ''
问题描述
这是我第一次尝试使用UI路由器。
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 ''
例外。有什么问题吗?
推荐答案
这种错误通常意味着,未加载(JS)code的某些部分。这是里面的UI SREF状态
缺失。
This kind of error usually means, that some part of (js) code was not loaded. That the state which is inside of ui-sref
is missing.
有 href=\"http://plnkr.co/edit/JpiliT6C6XGULRGQD6UF?p=$p$pview\">
There is a working example
的我不是在离子方面的专家,所以这个例子应该表明它会工作,但我使用了一些更多的花样(母公司为标签)的
这是一个有点调整状态高清
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
改进与标签命名视图的版本是在这里:<一href=\"http://plnkr.co/edit/Mj0rUxjLOXhHIelt249K?p=$p$pview\">http://plnkr.co/edit/Mj0rUxjLOXhHIelt249K?p=$p$pview
Improved version with named views in 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屋!