UI路由器不使用Angular无论如何

时间:2021-07-23 10:48:49

(angularJS 1.2.5 & ui-router 0.2.7) Please help its 4 in the morning and its been 2-3hrs since i'm stuck with this, flipped the code multiple times but cudn't make it run. In my index.html, I have the following code:

(angularJS 1.2.5&ui-router 0.2.7)请早上4点帮忙,自从我坚持使用它已经过了2-3个小时,多次翻转代码但不能让它运行。在我的index.html中,我有以下代码:

<div class="well sidebar-nav sidebar-slide">
   <ul class="nav nav-list" style="font-size:17px">
      <li class="nav-header">Demand Type</li>
        <li><a ui-sref="add14" data-toggle="tab">ADD-14</a></li>
        <li><a ui-sref="cash_purchase" data-toggle="tab">Cash Purchase</a></li>
        <li><a ui-sref="local_purchase" data-toggle="tab">Local Purchase</a></li>
   </ul>
</div>

        <div class="hero-unit" ui-view></div>

In my app.js, I have the following code:

在我的app.js中,我有以下代码:

var ODS = angular.module('ODS', ['ui.router','ngAnimate']);
    //Define Routing for app
    ODS.config(['$stateProvider', '$urlRouterProvider',
      function($stateProvider, $urlRouterProvider) {
          // For any unmatched url, redirect to /state1

        $urlRouterProvider
            .when('/add14', '/add14/create_order')
            .when('/cp', '/cp/create_order')
            .when('/lp', '/lp/create_order')
            .otherwise("/intro");
        $stateProvider
            .state('intro', {
                url: "/intro",
                templateUrl: "templates/core/intro.html"
            })
            .state("add14", {
                url: '/add14',
                templateUrl: 'templates/core/add14.html'
            })
                .state("add14.create_order", {
                    url: "/create_order",
                    templateUrl: "templates/ADD14/add14.create_order.html"
                })
                .state("add14.own_demand", {
                    url: "/own_demand",
                    templateUrl: "templates/ADD14/add14.own_demand.html"
                })
    }]);

In my add14.html, I have following code:

在我的add14.html中,我有以下代码:

<a ui-sref=".create_order">Create</a></button>
<a ui-sref=".own_demand">Own Demand</a>
<div ui-view></div>

In my add14.create_order.html & add14.own_demand.jsp i have sample code to print. Thank You for your patience!

在我的add14.create_order.html和add14.own_demand.jsp中,我有要打印的示例代码。感谢您的耐心等待!

3 个解决方案

#1


1  

Did you ever get this figured out? I'm running into a similar problem - I find that using <a href='#/url'> seems to work, but I can't access my states via ui-sref either. I've also noticed that the rendered html doesn't auto-generate an href corresponding to the state as the documentation said it would. Fairly confused why it's not working myself.

你有没有想到这个?我遇到了类似的问题 - 我发现使用似乎有效,但我无法通过ui-sref访问我的状态。我还注意到,渲染的html不会自动生成对应于状态的href,正如文档所说的那样。相当混淆为什么它不能自己工作。

#2


1  

Heads up: try to make sure you add the "ng-app" directive to your body tag (in your main template), otherwise, it seems angular-ui-router stuff, such as the ui-sref directive, will not be called.

抬头:尝试确保将“ng-app”指令添加到您的body标签(在主模板中),否则,似乎不会调用angular-ui-router的东西,例如ui-sref指令。

Example:

<html ng-app="myApp">...</html><!-- Nope. Don't do this -->


<html>...<body ng-app="myApp"></body></html><!-- Do this instead -->

#3


0  

You are using both $stateProvider and $urlRouterProvider. try just using $stateProvider instead of both as that could be where your error is. And you don't have controllers for each of your states. Hope this helps you.

您正在使用$ stateProvider和$ urlRouterProvider。尝试使用$ stateProvider而不是两者,因为这可能是你的错误所在。并且您没有为每个州设置控制器。希望这对你有所帮助。

#1


1  

Did you ever get this figured out? I'm running into a similar problem - I find that using <a href='#/url'> seems to work, but I can't access my states via ui-sref either. I've also noticed that the rendered html doesn't auto-generate an href corresponding to the state as the documentation said it would. Fairly confused why it's not working myself.

你有没有想到这个?我遇到了类似的问题 - 我发现使用似乎有效,但我无法通过ui-sref访问我的状态。我还注意到,渲染的html不会自动生成对应于状态的href,正如文档所说的那样。相当混淆为什么它不能自己工作。

#2


1  

Heads up: try to make sure you add the "ng-app" directive to your body tag (in your main template), otherwise, it seems angular-ui-router stuff, such as the ui-sref directive, will not be called.

抬头:尝试确保将“ng-app”指令添加到您的body标签(在主模板中),否则,似乎不会调用angular-ui-router的东西,例如ui-sref指令。

Example:

<html ng-app="myApp">...</html><!-- Nope. Don't do this -->


<html>...<body ng-app="myApp"></body></html><!-- Do this instead -->

#3


0  

You are using both $stateProvider and $urlRouterProvider. try just using $stateProvider instead of both as that could be where your error is. And you don't have controllers for each of your states. Hope this helps you.

您正在使用$ stateProvider和$ urlRouterProvider。尝试使用$ stateProvider而不是两者,因为这可能是你的错误所在。并且您没有为每个州设置控制器。希望这对你有所帮助。