0

Essentially what I want are numbers that I can pass into HTML based on a the number of times substring is matched from a response body.

I understand the best way to get that number is through regex. If I were to look for the number of occurrences of 'RED' for example I would want something like:

    var count1 = (proj.match(/RED/g) || []).length;

This is assuming that proj is a var with a response that has that in there.

Let's go with proj having too occurrences of 'RED'.

count1 should equal '2' or so I believe it should. So I want this to be stored for use with AngularJS so I go:

    $scope.red = count1;

And in the HTML I add {{red}}. This however, does not show 2. It also does not break the AngularJS and the response is also fine.

Can anyone tell me where I'm going wrong?

3
  • Could you please share a fiddle reproducing your issue? Commented Nov 17, 2016 at 11:07
  • your count looks fine and as per your steps assuming you are doing a match with case sensitive red should display 2 share your code its may be somewhere wrong in your angular implementation Commented Nov 17, 2016 at 11:08
  • put $scope.red = 'foo', if foo is rendered, then your problem is angularjs, not regex. for angulrajs, post your html and controllers setup Commented Nov 17, 2016 at 11:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.