0

My ngRoute breaks everytime I add another dependency. I want to add the 'moment-picker' to my app to pick dates and times but once I add the dependency to the module, I get the following error:

Uncaught Error: [$injector:modulerr]

On the error page under 'Discription' it shows 'Using ngRoute'.

This is my code:

var app = angular.module('weather', ['ngRoute', 'moment-picker']);

If I remove the 'moment-picker' the ngRoute works perfectly without any errors.

I have tried switching my links to my scripts around, but no luck.

4

2 回答 2

0

如果您使用的是Angular Moment Picker,请确保您已将相应的标签添加到您的index.html文件中(取决于您使用的版本):

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment-with-locales.js"></script>
<script src="//cdn.rawgit.com/indrimuska/angular-moment-picker/master/dist/angular-moment-picker.min.js"></script>
<link href="//cdn.rawgit.com/indrimuska/angular-moment-picker/master/dist/angular-moment-picker.min.css" rel="stylesheet">

<link>标签通常在开始时进入<head>标签内,而<script>标签通常在<body>标签内结束时出现。

于 2018-06-26T13:11:28.073 回答
0

似乎我的问题是添加脚本的顺序,以及我删除了“moment-withh-locales.js”脚本的顺序。

我现在的订单是:

<script src="scripts/angular.min.js" type="text/javascript"></script>
<script src="scripts/jquery-1.11.3.min.js" type="text/javascript"></script>
<script src="scripts/bootstrap.min.js" type="text/javascript"></script>
<script src="scripts/jquery.easing.min.js" type="text/javascript"></script>
<script src="scripts/angular-route.js"></script>

<script src="scripts/moment-with-locales.js" type="text/javascript"></script>
<script src="scripts/moment.min.js" type="text/javascript"></script>
<script src="scripts/angular-moment-picker.min.js" type="text/javascript"></script>
<link href="css/angular-moment-picker.min.css" rel="stylesheet" type="text/css"/>

<script src="scripts/app.js" type="text/javascript"></script>

在 app.js 我的代码如下:

var app = angular.module('weather', ['ngRoute', 'moment-picker']);

app.config(function($routeProvider) 
{
    $routeProvider
    .when("/", {
      templateUrl : "home.php"
    })
    .when("/page1", {
      templateUrl : "page1.php"
    });
});

app.config(['momentPickerProvider', function (momentPickerProvider) {momentPickerProvider.options(
{
    /* Picker properties */
    locale:        'en',
    format:        'L LTS',
    minView:       'decade',
    maxView:       'minute',
    startView:     'year',
    autoclose:     true,
    today:         false,
    keyboard:      false,

    /* Extra: Views properties */
    leftArrow:     '&larr;',
    rightArrow:    '&rarr;',
    yearsFormat:   'YYYY',
    monthsFormat:  'MMM',
    daysFormat:    'D',
    hoursFormat:   'HH:[00]',
    minutesFormat: moment.localeData().longDateFormat('LT').replace(/[aA]/, ''),
    secondsFormat: 'ss',
    minutesStep:   5,
    secondsStep:   1
    });
}]);

谢谢大家的帮助。

于 2018-06-26T14:14:45.450 回答