Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Latest commit

 

History

History

conditionally_hiding_an_element

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Conditionally hiding an element

Shows conditional boolean attributes using the ?= syntax.

The code

How it works

You can set an element's hidden property using hidden$=. For example:

<p hidden$="{{shortView}}">
  ...
</p>

If shortView is true the paragraph is displayed, otherwise the paragraph is hidden.

The MyElement class (my_element.dart) defines the toggleView method which toggles the boolean variable, shortView. This variable must be defined as observable.

@property bool shortView = true;

@reflectable
void toggleView([_, __]) {
  set('shortView', !this.shortView);
}

The template code (my_element.html) defines a paragraph where the hidden tag is bound to the value of shortView.

The Big Lebowski

'Dude' Lebowski, mistaken for a millionaire Lebowski, seeks restitution for his ruined rug and enlists his bowling buddies to help get it.

Toggle View

Tapping the provided button calls the toggleView method, which toggles the display of the paragraph.

More information