0

I am having a condition in Rails as:

if @user.permissions.include?('show_reports')

I need to check the above condition in angular pages. How to write in ng-if condition?

For example there is a dropdown class as

.dropdown
  %h1 This is example

In all the other pages, they have written:

.dropdown{ng-if => ...}

but couldn't write for above condition. Please help.

2
  • For ng-if you need to have angular variables and condition. You can't use a rails if condition inside 'ng-if' Commented Dec 8, 2015 at 4:40
  • @Devd - I mean like user.permissions.showReports like that.. I will add code in angular. But just need how to translate from Rails to angular. Commented Dec 8, 2015 at 6:32

1 Answer 1

1
<script>
    var myapp = angular.module('myapp', []);
    myapp.controller('Controller', Controller);

    function Controller(){
       var scope = this;
       scope.has_reports = <%= @user.permissions.include?('show_reports') %>;
    }
</script>

And then use it like 'ng-if' => "ctrl.has_reports",

here ctrl is ng-controller

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.