简体   繁体   English

如何在具有不同路径文件的角度中将一个视图移动到另一个视图?

[英]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.

相关问题 如何将一个视图移动到另一个视图? - how to move one view to another view? 如何在 Express 中将请求正文的数据从一条路由移动到另一条路由 - How to move data of request body from one route to another in Express 如何在Angular JS路由中将多个控制器添加到一个视图 - How to add multiple controllers to one view in Angular JS route 如何在Angular JS中将一个表行移动到另一个表? - how to move one table row to another table in angular js? 如何以角度保留路线的视图 - How to persist the view of a route in angular 如何阻止Angular UI路由器将可选参数从一条路由传递到完全不同的路由 - How to stop Angular UI Router passing optional params from one route to completely different route 大家好, 如何使用一个路由文件中的变量到另一个路由文件? - Hi all, How can use a variable from one route file to another route file? 使用Angular和ng-route将视图嵌入另一个视图 - Embedding a view in another view using Angular and ng-route 如何将输入的数据从一个html文件移动到其ts文件,然后再移动到另一个组件文件? - How to move the entered data from one html file to its ts file and then to another component file? 页面上的超时请求重定向无法路由到另一个角度视图 - Timeout request on page for redirect is unable to route to another angular view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM