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

时间:2015-01-14 09:25:48

标签: javascript angularjs angularjs-directive angularjs-scope angular-ui-router

我试图将一个视图移动到另一个视角。实际上我能够显示第一个视图。在该视图中有按钮。点击按钮我试图转到下一页但是我收到错误按钮点击为什么?

这是我的傻瓜 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')
    }
  }

})();

2 个答案:

答案 0 :(得分:1)

updated working plunker state.go需要州名

function firstcont($scope,$state) {
    $scope.clickEvent=function(){
     // instead of this
     // $state.go('/second')
     // we need this
     $state.go('secondapp')
    }
}

因为您的州定义为:

$stateProvider
    .state('secondapp', {
        url: '/second',
        ...

检查updated version here

答案 1 :(得分:0)

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"
            })