pat
pat

Reputation: 5797

AngularJS setting default value for ng-hide

Im having a issue with hiding elements. Basically i want to set defaults for what elements are hidden/shown when the page is loaded.

Im hiding my elements via the ng-hide that is bound to a model that is set from the controller, and ng-repeated over in the view.

The checkbox is bound correctly, but the content in not hidden by default, you will have to click the checkbox twice for it to correctly hide the element.

Demo is found here: Plunker

Upvotes: 2

Views: 4315

Answers (2)

Chandermani
Chandermani

Reputation: 42669

The first time odd behaviour is due to you mobile property checkedContainer has not been created till the binding is evaluate based on your interaction with the checkboxes.

In the controller if you do

$scope.checkedContainer=true; your code would work.

Upvotes: 1

Ivan Chernykh
Ivan Chernykh

Reputation: 42176

It works when these models are defined. You can use ng-init for this purpose:

 ng-init="$parent[col.model]=col.checked"

Working plnk: http://plnkr.co/edit/pUAufB?p=preview

Upvotes: 2

Related Questions