如何调试:“undefined不是函数”

时间:2014-05-13 17:18:05

标签: jquery angularjs

var myAppControllers = angular.module('myAppControllers', []);

myAppControllers.controller('ToolsCtrl', ['$scope', '$http', '$routeParams', '$cookies', '$location',
  function ($scope, $http, $routeParams, $cookies, $location) {
    $scope.tag = function(messageTags) {
      console.log(messageTags);
      if ($scope.tags) {
        return $scope.tags.replace(/\s*,\s*/g, ',').split(',').every(function(tag) {
          return messageTags.tags.some(function(objTag){
            return objTag.indexOf(tag) !== -1;
          });
        });
      }
      else {
        return true;
      }
    };
...
<div ng-controller="ToolsCtrl" class="voffset2">
  <div class="input-group input-group-lg">
    <span class="input-group-addon">?</span><input type="text" ng-model="tags" name="search" class="form-control">
   </div>

   <div ng-repeat="tool in filtered = (tools | filter:tag)" class="span4 tags-wrapper">
      <span ng-repeat="tagWithMeta in tool.tagsWithMeta" class="tag-box">{{tagWithMeta.tag}}</span>             
   </div>
</div>

错误似乎在这里:return messageTags.tags.some(function(objTag){

我不太记得它是否曾经有效,因为我真正将我的应用程序集成到wordpress中。另一篇帖子提到了s.th.关于jquery没有conflcit模式: TypeError: 'undefined' is not a function (evaluating '$(document)')

我不认为一个plunkr会有所帮助,但这里有一个wordpress演示网站: http://360-disrupt.de/test-2/

1 个答案:

答案 0 :(得分:0)

问题是标签格式不正确。它们保存在这样的字符串中:[“'tagA','tagB'”]但它们必须是这样的数组:[“tagA”,“tagB”]。

function ($scope, $http, $routeParams, $cookies, $location) {
    $scope.tag = function(message) {
      var messageTags = message.tags.replace(/[']/g, "");
      messageTags = messageTags.split(",");
      console.log(messageTags);
      if ($scope.tags) {
        $scope.tags=$scope.tags.toLowerCase();
        return $scope.tags.replace(/\s*,\s*/g, ',').split(',').every(function(tag) {
          return messageTags.some(function(objTag){
            return objTag.indexOf(tag) !== -1;
          });
        });
      }
      else {
        return true;
      }
    };