2

I've looked through a number of responses and can't for the life of me figure out why my code isn't working!

I want to apply a simple custom filter to a variable passed from the controller. The room-price value displays fine. however, when I add the price-per-night filter the value disappears.

Can anyone suggest a solution? Thanks

Template

<div class="h3 left-align p1" ng-bind="room.price | price-per-night"></div>

Controller

routerApp.controller('MyController', function($scope) {
    $scope.rooms = [
    {
        name: 'Basic',
        price: 50
    }]
});

Filter

routerApp.filter("price-per-night",
    function() {
        return function(price) {
            var output = '£' + price + ' ' + 'per night';
            return output;
        };
    }
);

1 Answer 1

2

Name your filter pricePerNight. - is not allowed in the name:

routerApp.filter("pricePerNight",
    function() {
        return function(price) {
            var output = '£' + price + ' ' + 'per night';
            return output;
        };
    }
);

(You still use price-per-night in your HTML)

Sign up to request clarification or add additional context in comments.

Comments

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.