[英]how to move one view to another in angular having different route file?
I am trying to move one view to another in angular .Actually I am able to show first view .And in that view there is button .On click of button I am trying to go to next page But I am getting error on button click why ? 我试图将一个视图以角度移动到另一个视图。实际上,我可以显示第一个视图。在那个视图中有一个按钮。单击按钮时,我试图转到下一页,但是单击按钮时出现错误,为什么?
here is my plunker http://plnkr.co/edit/2cMimMX6xS0rTB7lJOQx?p=preview 这是我的朋克http://plnkr.co/edit/2cMimMX6xS0rTB7lJOQx?p=preview
(function() {
'use strict';
angular
.module('firstApp')
.controller('firstcont', firstcont);
firstcont.$inject = ['$scope',"$state"];
function firstcont($scope,$state) {
$scope.clickEvent=function(){
$state.go('/second')
}
}
})();
There is updated working plunker The state.go requires state name 有更新的工作插件 The state.go需要状态名称
function firstcont($scope,$state) {
$scope.clickEvent=function(){
// instead of this
// $state.go('/second')
// we need this
$state.go('secondapp')
}
}
because your state is defined as: 因为您的状态定义为:
$stateProvider
.state('secondapp', {
url: '/second',
...
Check the updated version here 在这里检查更新的版本
Here is the plunker:-
http://plnkr.co/edit/Y6v7ZUB1biVdWgeYpqDb?p=preview"
You need to change
$state.go('/second') to $state.go('second')
And add the state
.state('second', {
url: '/second',
views: {
app: { templateUrl: 'second.html' }
},
controller:"firstcont"
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.