在AngularJS

时间:2015-07-07 00:30:43

标签: javascript angularjs html5

我正在尝试删除网址中的哈希并使用 $ locationProvider.html5Mode(true); 。但是我得到以下内容:

错误:[$ rootScope:infdig] http://errors.angularjs.org/1.4.2/ $ rootScope / infdig?p0 = 10& p1 =%5B%5D

如果我注释掉 $ locationProvider.html5Mode(true); ,我不会收到错误。

我尝试了不同论坛的一些推荐,但都没有。

任何帮助将不胜感激。谢谢!

这是我的代码:

parserconfigApp.js

var app = angular.module('parserconfigApp', ['ngRoute']);

app.controller('ParserConfigController', ['$scope', '$location', function($scope, $location){
    $scope.recordTypes = recordTypes;

    $scope.remove = function(index) {
        $scope.recordTypes.splice(index, 1);
    }    

    $scope.changeView = function(view) {
        $location.path(view);
    }
}]);


app.controller('AddRecordTypeController', ['$scope', function($scope){
    $scope.recordTypes = recordTypes;

    $scope.remove = function(index) {
        $scope.recordTypes.splice(index, 1);
    }    
}]);


app.config(function($routeProvider, $locationProvider) {
        $routeProvider
            .when('/', {
                templateUrl: 'parserconfig.html',
                controller: 'ParserConfigController'
            })
            .when('/recordTypeList', {
                templateUrl: 'parserconfig.html',
                controller: 'ParserConfigController'
            })
            .when('/addRecordType', {
                templateUrl: 'templates\add-record-type.html',
                controller: 'AddRecordTypeController'
            })
            .otherwise({
                redirectTo: '/recordTypeList'
            });

            // use the HTML5 History API
            $locationProvider.html5Mode(true);
        });

var recordTypes = [
'Boot Record',
'Card Uptime Record',
'Stack Trace'
];

parserconfig.html

<!DOCTYPE html>
<html ng-app='parserconfigApp'>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

    <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>

    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <script src="https://code.angularjs.org/1.4.0/angular-route.min.js"></script>

    <base href="C:\Users\myusername\Documents\AngularJS\Polaris\AngularJS\Exercises\parser_ui\">
    <title>Parser Config</title>
</head>

<body>
<div ng-controller='ParserConfigController as parserConfig'>

    <h1>Record Types</h1>


    <table style="font-size: medium; width: 50%; table-layout: fixed" ng-repeat='recordType in recordTypes'>
        <tr>
            <td><a>{{recordType}}</a></td>
            <td><button ng-click="remove($index)">Remove</button><td>
        </tr>
    </table>

    <button ng-click="changeView('addRecordType')">Add</button>

</div>
    <script type="text/javascript" src="parserconfigApp.js"></script>
</body>
</html>            

0 个答案:

没有答案