0
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>

The error seems to be here: return messageTags.tags.some(function(objTag){

I don't quite remember if it ever worked since I really integrated my app into wordpress. Another posts mentions s.th. about a jquery no conflcit mode: TypeError: 'undefined' is not a function (evaluating '$(document)')

I don't think a plunkr will be helpful, but here is a wordpress demo site: http://360-disrupt.de/test-2/

Community
  • 1
  • 1
Andi Giga
  • 3,744
  • 9
  • 38
  • 68
  • Thats how It should behave: http://360-disrupt.de/app/#/search – Andi Giga May 13 '14 at 17:19
  • Seeing as you only have one function call here: `return messageTags.tags.some(function(objTag){`, some() is not defined... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some for browser support. – James_1x0 May 13 '14 at 17:54
  • I basically copied it from here: https://coderwall.com/p/-t1w2g In the other link and on my xampp the function worked, just in the wordpress version it doesn't work. So is this because of the no conflict mode & the missing argument? – Andi Giga May 13 '14 at 21:50

1 Answers1

0

The problem was that the tags were not in the right format. They were saved in a string like this: ["'tagA', 'tagB'"] but they needed to be an array like this: ["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;
      }
    };
Andi Giga
  • 3,744
  • 9
  • 38
  • 68