Javascript State.go()在地址页中显示url,但不显示';t刷新html视图
我用angularJs在Ionic上乱搞时遇到了一个问题,问题是在我尝试开发登录页面时路由系统中。 在代码的控制器部分,我将尝试加载一个名为“dash”的欢迎页面,其中包含Javascript State.go()在地址页中显示url,但不显示';t刷新html视图,javascript,html,angularjs,ionic-framework,ionic,Javascript,Html,Angularjs,Ionic Framework,Ionic,我用angularJs在Ionic上乱搞时遇到了一个问题,问题是在我尝试开发登录页面时路由系统中。 在代码的控制器部分,我将尝试加载一个名为“dash”的欢迎页面,其中包含state.go(psc.dash) 这是我的控制器.js: angular.module('starter.controllers', []) .controller('LoginCtrl', function($location, $state) { var user = this;
state.go(psc.dash)
这是我的控制器.js:
angular.module('starter.controllers', [])
.controller('LoginCtrl', function($location, $state) {
var user = this;
user.login = function() {
console.log("LOGIN user: " + user.email + " - PW: " + user.password);
setTimeout(function() {
state.go('psc.dash');
}, 20);
};
})
.controller('DashCtrl', function($scope, $location) {});
这是我的App.js:
.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
$stateProvider
.state('login', {
url: "/login",
views: {
'login': {
templateUrl: "templates/login.html",
controller: "LoginCtrl"
}
}
})
.state('psc', {
url: "/psc",
abstract: true,
templateUrl: "templates/psc.html"
})
.state('psc.dash', {
url: "/dash",
views: {
'psc-dash': {
templateUrl: "templates/dash.html",
controller: "DashCtrl"
}
}
})
;
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/login');
});
这是我的login.html
<div class="list list col span_1_of_2 " ng-controller="LoginCtrl as loginCtrl">
<label class="item item-input">
<span class="input-label">E-mail</span>
<input type="text" ng-model="loginCtrl.email">
</label>
<label class="item item-input">
<span class="input-label">password</span>
<input type="password" ng-model="loginCtrl.password">
</label>
<div>
<div class="col span_2_of_3"><a href=" ">forgot password ? </a></div>
<button class="button button-positive col span_1_of_3" ng-click="loginCtrl.login()">
connect
</button>
</div>
</div>
电子邮件
密码
连接
问题是,当我单击“连接”按钮时,url“/psc/dash”出现在地址栏中,但登录视图保持显示,并且页面不会重新加载新的html视图。编辑
这是错误的。ui路由器
文档中存在差异:
原因是,尽管您的
'psc.dash'
嵌套状态被定义为'psc'
状态的子级,但分配给它的URL不会自动以其父级URL作为前缀
您想将'psc.dash'
状态定义更改为:
.state('psc.dash', {
url: "/psc/dash",
views: {
'psc-dash': {
templateUrl: "templates/dash.html",
controller: "DashCtrl"
}
}
})
请查看以下内容,了解原因:
子状态从父状态继承什么?
子州从父州继承以下内容:
服务是
$state
,因此代码应该是:
$state.go('psc.dash');
您可以删除HTML中的控制器定义:
<div class="list list col span_1_of_2" ng-controller="LoginCtrl as loginCtrl">
</div>
您不需要定义控制器两次
您的login.html模板未使用
。如果能看到你的项目的成功,那将是一件有趣的事情
另一件我不确定的事情是州的定义。如果视图登录未包装在另一个容器中,则应这样编写:
.state('login', {
url: "/login",
templateUrl: "templates/login.html",
controller: "LoginCtrl as loginCtrl"
})
解决方案:
我的psc路由应命名为“login”,以便识别
.state('psc', {
url: "/psc",
views: {
'login': {
abstract: true,
templateUrl: "templates/psc.html"
}
}
})
我更改了它,但它不是一个解决方案,它将在导航器的地址栏中显示“/psc/psc/dash”,但仍然没有重新加载页面。您还使用了命名视图
“psc-dash”
。在HTML中,是否使用name
属性声明
元素?像这样:
是的,我在psc.html中添加了它,我尝试将它添加到dash.html中,但它并没有解决我在Ionic命令选项卡中遇到的问题:html已更改:…/psc.html无法更新实时重新加载:{[Error:connect econnreference]代码:“econnreference”,errno:“econnreference”,syscall:“connect”}已解决,问题是我的psc路由在视图中没有名称视图。
.state('login', {
url: "/login",
templateUrl: "templates/login.html",
controller: "LoginCtrl as loginCtrl"
})
.state('psc', {
url: "/psc",
views: {
'login': {
abstract: true,
templateUrl: "templates/psc.html"
}
}
})