Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript &引用;TypeError:无法调用方法';匹配';“未定义”的定义;角JS指令中的Morris JS_Javascript_Jquery_Angularjs_Morris.js - Fatal编程技术网

Javascript &引用;TypeError:无法调用方法';匹配';“未定义”的定义;角JS指令中的Morris JS

Javascript &引用;TypeError:无法调用方法';匹配';“未定义”的定义;角JS指令中的Morris JS,javascript,jquery,angularjs,morris.js,Javascript,Jquery,Angularjs,Morris.js,我试图在Angular JS中使用Morris JS图,下面是我的代码 控制台中有一个错误,指向“new Morris.Line({)”行。我该怎么办?谢谢 Reporting.directive('ngMorrison', function() { return { //require: '^ngModel', scope: { ngModel: '=' }, template: '<div id

我试图在Angular JS中使用Morris JS图,下面是我的代码

控制台中有一个错误,指向“new Morris.Line({)”行。我该怎么办?谢谢

Reporting.directive('ngMorrison', function() {
    return {
        //require: '^ngModel',
        scope: {
          ngModel: '='
        },
        template: '<div id="call-chart" class="graph">test</div>',
        controller: ['$scope', '$http', '$q', function($scope, $http, $q) {
          $scope.getCalls = function() {
            var defer = $q.defer();
            $http({method: 'GET', url: '/dashboard/'}).
                success(function (data, status, headers, config) {
                    defer.resolve(data);
                }).error(function (data, status, headers, config) {
                    defer.reject(status);
                });
            return defer.promise;
          }
        }],
        link: function(scope, iElement, iAttrs, ctrl) {
            calls = scope.getCalls();
            // get list of users
            new Morris.Line({
              // ID of the element in which to draw the chart.
              element: "call-chart",
              // Chart data records -- each entry in this array corresponds to a point on
              // the chart.
              data: [
                { year: '2008', value: 20 },
                { year: '2009', value: 10 },
                { year: '2010', value: 5 },
                { year: '2011', value: 5 },
                { year: '2012', value: 20 }
              ],
              // The name of the data record attribute that contains x-values.
              xkey: '{year}',
              // A list of names of data record attributes that contain y-values.
              ykeys: ['value'],
              // Labels for the ykeys -- will be displayed when you hover over the
              // chart.
              labels: ['Value']
            });
        }
    };
});
Reporting.directive('ngMorrison',function(){
返回{
//要求:“^ngModel”,
范围:{
ngModel:“=”
},
模板:“测试”,
控制器:['$scope','$http','$q',函数($scope,$http,$q){
$scope.getCalls=function(){
var defer=$q.defer();
$http({method:'GET',url:'/dashboard/'})。
成功(函数(数据、状态、标题、配置){
延迟解析(数据);
}).error(函数(数据、状态、标题、配置){
推迟、拒绝(状态);
});
回报、承诺;
}
}],
链接:功能(范围、IELENT、iAttrs、ctrl){
calls=scope.getCalls();
//获取用户列表
新莫里斯线({
//要在其中绘制图表的元素的ID。
元素:“呼叫图”,
//图表数据记录——此数组中的每个条目对应于
//图表。
数据:[
{年份:'2008',价值:20},
{年份:'2009',价值:10},
{年份:'2010',值:5},
{年份:'2011',价值:5},
{年份:'2012',价值:20}
],
//包含x值的数据记录属性的名称。
xkey:“{year}”,
//包含y值的数据记录属性的名称列表。
ykeys:['value'],
//当您将鼠标悬停在
//图表。
标签:['Value']
});
}
};
});
这是我在查看控制台时遇到的错误:

TypeError: Cannot call method 'match' of undefined
    at Object.t.parseDate (eval at <anonymous> (http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:3:4904), <anonymous>:1:9523)
    at n.eval (eval at <anonymous> (http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:3:4904), <anonymous>:1:3297)
    at n.t.Grid.r.setData (eval at <anonymous> (http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:3:4904), <anonymous>:1:3888)
    at n.r (eval at <anonymous> (http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:3:4904), <anonymous>:1:1680)
    at new n (eval at <anonymous> (http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:3:4904), <anonymous>:1:11953)
    at link (http://localhost:8000/static/js/app/directives/directives.js:59:23)
    at j (http://localhost:8000/static/js/libs/angular/angular.min.js:43:157)
    at e (http://localhost:8000/static/js/libs/angular/angular.min.js:38:463)
    at e (http://localhost:8000/static/js/libs/angular/angular.min.js:38:480)
    at e (http://localhost:8000/static/js/libs/angular/angular.min.js:38:480) <div ng-morrison="" class="ng-isolate-scope ng-scope"> angular.min.js:61
TypeError:无法调用未定义的方法“match”
在Object.t.parseDate(eval at(http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:3:4904), :1:9523)
在n.eval(eval在(http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:3:4904), :1:3297)
at n.t.Grid.r.setData(评估at(http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:3:4904), :1:3888)
在n.r(评估在(http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:3:4904), :1:1680)
在新n(评估在(http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:3:4904), :1:11953)
在链接(http://localhost:8000/static/js/app/directives/directives.js:59:23)
在j(http://localhost:8000/static/js/libs/angular/angular.min.js:43:157)
在e(http://localhost:8000/static/js/libs/angular/angular.min.js:38:463)
在e(http://localhost:8000/static/js/libs/angular/angular.min.js:38:480)
在e(http://localhost:8000/static/js/libs/angular/angular.min.js:38:480)angular.min.js:61

您看到的错误是Morris遇到xkey属性问题时导致的。请将xkey值从{year}更改为'year',这样可以解决问题

请使用以下示例:

我是Angular JS新手,所以不知道从哪里开始时很难调试。我只是想找人给我指出正确的方向。首先在问题内部发布完整的错误堆栈。问题是日期格式。这是console中的错误(b.parseDate@morris.min.JS:6)