SD Dev
SD Dev

Reputation: 345

Hiding ng-repeat expression & filter logic in html?

I have a simple ng-repeat with a filter on it below. However in my html I see my logic in the html. Is there a way to hide this?

<div ng-repeat="row in rowData.players| filter:{name:"Dan"})">
{{row.name}}
</div>

When I look at my page though all my repeated divs have the above logic expression in them. Is there a directive or best practice to hide this?

Upvotes: 0

Views: 94

Answers (3)

Jai Kamat
Jai Kamat

Reputation: 33

Rather than filtering in your html template, you can create a scoped variable that holds these filtered values, and then iterate over them. That way users who inspect your DOM will not see the filtered values.

For example, in your controller, you could have:

.controller('SomeCtrl', function($scope, $filter) {

    $scope.rowData.players = $filter('someFilter')(filterArgs1, filterArgs2, etc);

})

Upvotes: 1

Asaf Lopez
Asaf Lopez

Reputation: 557

You have an extra ")" at the end of your:

"row in rowData.players| filter:{name:'Dan'})"

not sure if it has to be there or not, check it out, also @Divyesh is right, try to use simple ticks '' instead of "" when already enclosed by doble ticks

Upvotes: 1

divyesh
divyesh

Reputation: 332

<div ng-repeat="row in rowData.players| filter:{name:'Dan'})"> {{row.name}} </div>

Try using single quotes instead of double quotes.

Upvotes: 2

Related Questions