0

I am by setting the display type of a dashboard and came across this problem, how to make a if else in angular.

Is there a better way to do this?

<div ng-if="'CONFIG.dashboard.rows == 1'" layout="column" flex>
<div ng-if="'CONFIG.dashboard.rows > 1'" layout="row" flex>

RESOLVED:

<div ng-switch on="CONFIG.dashboard.rows" flex>

    <div ng-switch-when="1" layout="column" flex layout-wrap>

        <div ng-repeat="wdg in CONFIG.widgets" flex='100' ng-include="wdg.template"></div>

    </div>


    <div ng-switch-default layout="row" flex layout-wrap>

        <div ng-repeat="wdg in CONFIG.widgets" flex='50' ng-include="wdg.template"></div>

    </div>

</div>
4
  • Did you have a look at angular views? docs.angularjs.org/api/ngRoute/directive/ngView Commented Jul 23, 2015 at 20:22
  • I just want to put an element or change it, depending on the settings made. With views I would have a lot more work, but thanks for the reply. Commented Jul 23, 2015 at 20:26
  • what is the actual problem? Commented Jul 23, 2015 at 20:36
  • possible duplicate of If else conditions in angularjs templates Commented Jul 23, 2015 at 20:37

1 Answer 1

2

You could use the ngSwitch directive to accomplish this.

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

1 Comment

I can use on one line?

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.