角路由无法以期望的方式工作



我正在使用Angular并尝试路由到页面。它在任何地方都可以使用,但是在下面的代码中,当我尝试路由时,我看到URL移至所需的页面,但从触发的地方又回到同一页面。我不确定为什么会这样。

这是我称为方法

的HTML
<button  ng-click="proposalForm()" >Request</button>

在我的控制器中,我只是想路由到另一个页面。当我单击按钮时,它将路由到"提案"页面,但很快从触发此触发的位置返回相同。我想念什么吗?它在所有其他地方都对我有用。

$scope.proposalForm = function() {
    $location.path('/proposal');
}

当我尝试使用dataTarget访问它时,它包括JSP,但是当我尝试完全路由到另一个页面时,它不起作用。还有其他方法吗,我可以将其路由到其他JSP

这是我的路由器代码,它具有正确的建议途径,我不确定是否由于某种原因将其路由到默认值

Bid.config(function($routeProvider) {
    .when('/proposal', {
		templateUrl : '/Bid/proposal',
		controller : 'homeController'
	}).otherwise({
		redirectTo : '/'
	});
});  

使用项目中的库 <script data-require="ui-router@*" data-semver="0.2.8" src="http://angular-ui.github.io/ui-router/release/angular-ui-router.js"></script>

,然后config.js

.state('proposal', {
          url: '/proposal',
templateUrl: 'templates/proposal.html',
controller: 'NewCtrl'
        });
    $urlRouterProvider.otherwise('/auth/login');

和控制器

app.controller('NavCtrl', function ($scope, $location, $state, Post, Auth) { 
    $scope.create = function() {      
      $state.go("proposal"); 
    };
  });

和app.js

var abc= angular.module('abc', [
       'ui.router'
]);

如果要使用AngularJS创建一个单个页面应用程序(SPA),则应使用$ State Service,而不是$位置服务。无论如何,代码在语法上似乎正确,也许您可以添加路由器代码?

最新更新