1

This will be very easy for you Angular monsters out there. I have two views ( a list view and a grid view) each in a partial html that is injected via ng-include on a click of a button. Like this:

<div class = "bar">
    <h1>Contacts</h1>
    <a href="#" class="list-icon" ng-class="{active: layout == 'list'}" ng-click="layout = 'list'"></a>
    <a href="#" class="grid-icon" ng-class="{active: layout == 'grid'}" ng-click="layout = 'grid'"></a>
</div>
<div ng-show="layout == 'list'" class="list">
    //ng-include for the list page is here
</div>
<div ng-show="layout == 'grid'" class="grid">
    //ng-include for the grid page is here
</div>

How can I initiate one of those views? grid for instance. I imagine it's done with ng-init. but I can't figure it out

Thanks!

1 Answer 1

1

You can initialize an variable either using ng-init or in controller variable declaration:

  1. ng-init="layout === 'list'"
  2. $scope.layout = 'list'
Sign up to request clarification or add additional context in comments.

2 Comments

Just minutes later I realized I could do this also. ng-init="layout = 'grid'" . But I like your controller-way better. I'm using yours. Thanks! I knew this would be easy.
Actually, for future visitors, you should add the ng-init way to your answer. Option1 and Option2 is a much more completed answer

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.