<基本href>原因;[$rootScope:infdig]”;错误

<base href> causes "[$rootScope:infdig] " error

本文关键字:infdig 错误 rootScope 基本 lt href gt 原因      更新时间:2023-09-26

我试图通过url将两个参数从first.html发送到second.html,并使用routeParamssecond.html中获取值。我已经将基本标记设置为<base href="file:///D:/abhilash/node/angapp/"/>,单击按钮时,输入文本框中的参数应该通过url传递。

第一个.html:

   <!DOCTYPE html>
<html ng-app="myapp">
<head>
    <title></title>
    <base href="file:///D:/abhilash/node/angapp/"/>
</head>
<body>
<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="angular-route.js"></script>
<script type="text/javascript" src="controller.js"></script>
<div ng-controller="firstController">
    First name:<input type="text" ng-model="firstName"><br>
    Last name:<input type="" ng-model="lastName"><br>
    <input type="button" ng-click="loadView()" value="submit" name="">
</div>
</body>
</html>

Second.html:

    <!DOCTYPE html>
<html ng-app="myapp">
<head>
    <title></title>
<base href="file:///D:/abhilash/node/angapp/"/>
</head>
<body>
<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="angular-route.js"></script>
<script type="text/javascript" src="controller.js"></script>
<div ng-controller="secondController">
 {{firstName}}
</div>
</body>
</html>

这是控制器:

(function(){
var app = angular.module('myapp', ['ngRoute']);
app.config(function($routeProvider,$locationProvider){
    $routeProvider.when('/first',{
        templateUrl:'/first.html',
        controller: 'firstController'
    })
    .when('/second/:firstName/:lastName',{
        templateUrl:'/second.html',
        controller:'secondController'
    })
    .otherwise({
        redirectTo:'/first'
    })
    $locationProvider.html5Mode(true);
})

app.controller('firstController',function($scope,$location){
        $scope.firstName="";
        $scope.lastName="";
        $scope.loadView = function()
        {
            $location.path('second/'+$scope.firstName +"/" +$scope.lastName);
            console.log($location.url());
        }
    })
    .controller('secondController',function($scope,$routeParams){
        $scope.firstName = $routeParams.firstName;
        $scope.lastName = $routeParams.lastName;
    })
}());

在此处检查此代码如果您正在将应用程序部署到根上下文中(例如。https://myapp.com/),将基本URL设置为/:

<head>
  <base href="/">
  ...
</head>

如果您正在将应用程序部署到子上下文中(例如。https://myapp.com/subapp/),将基本URL设置为子文本的URL:

<head>
  <base href="/subapp/">
  ...
</head>