【问题标题】:how to properly call routing in angular?如何正确调用角度路由?
【发布时间】:2017-06-17 22:14:26
【问题描述】:

我有一个主模块,里面有一些路线。 我还有几个模块,所有这些都包含在我的主模块中。从我的家庭模块功能之一,我正在尝试路由但出现错误。同一个应用程序上的其他功能完美路由。已经半天了,还是解决不了。下面是代码和错误堆栈请任何帮助都会很棒

  var app = angular.module("mainModule", ['ngRoute','homeModule']);


app.config(function($routeProvider) {
    $routeProvider
    .when("/", {
        controller : "homeController",
        templateUrl : "main.html"
    })
     .when("/ac-repair", {
        templateUrl : "views/ac-service-repair.html",
        controller : "formController"
      })
      });
      
      //home module
      var app = angular.module("homeModule", ['ngRoute']);


    app.controller("homeController", function ($scope, $http, $location, $rootScope) {
 
       $scope.$watch("selectedService", function (newValue, oldValue) {
            // your code goes here...
            if (newValue != oldValue) {

                var name = $scope.selectedService.name;
              
                if (name == "AC Service & Repair") {
       
           //working fine here
           $location.path('/ac-repair');
                    return;
                }
            
            }
        });
        ////


//not working route in this function
        $scope.serviceClicked=function(name)
        {
           
        if (name == 'AC Service & Repair') {
      
        console.log("reached here!!");
      
      
                  $location.path('/ac-repair');
                   return;
                }
              
                  }
    });
    
   // error
   Uncaught Error: Syntax error, unrecognized expression: [name=]
    at Function.ga.error (jquery.min.js:2)
    at ga.tokenize (jquery.min.js:2)
    at ga.select (jquery.min.js:2)
    at Function.ga [as find] (jquery.min.js:2)
    at r.fn.init.find (jquery.min.js:2)
    at r.fn.init (jquery.min.js:2)
    at r (jquery.min.js:2)
    at HTMLAnchorElement.<anonymous> (<anonymous>:6:43)
    at HTMLAnchorElement.dispatch (jquery.min.js:3)
    at HTMLAnchorElement.q.handle (jquery.min.js:3)
    

//编辑: 我观察得很仔细;它会在浏览器中更改路径一秒钟,然后返回.. 到 '/'

【问题讨论】:

    标签: angularjs ngroute routeconfig


    【解决方案1】:

    我终于找到了解决方案。这是一个愚蠢的错误..我在调用函数时也将 href="#" 与我的代码一起放置..因此它一团糟。任何方式都非常感谢您在这里查看。我希望这可以帮助任何其他新手

    【讨论】:

      猜你喜欢
      • 2017-04-21
      • 2021-12-19
      • 1970-01-01
      • 1970-01-01
      • 2018-09-05
      • 1970-01-01
      • 2020-04-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多