Runoob Tutorial ArchiveEnglish

AngularJS HTML DOM

AngularJS HTML DOM


AngularJS provides directives to bind application data to attributes of HTML DOM elements.


ng-disabled directive

ng-disabledThe directive directly binds application data to the disabled attribute of HTML.

AngularJS instance

<

div

ng-app=

""

ng-init=

"mySwitch=true"

<

p

<

button

ng-disabled=

"mySwitch"

Click me!

<

/button

<

/p

<

p

<

input

type=

"checkbox"

ng-model=

"mySwitch"

Button

<

/p

<

p

{{ mySwitch }}

<

/p

<

/div

Try it »

Instance explanation:

ng-disabledBinds the application data "mySwitch" to the disabled attribute of HTML.

ng-modelBinds "mySwitch" to the content (value) of the HTML input checkbox element.

IfmySwitchistrue, the button will be unavailable:

<

p

<

button

disabled

Click me!

<

/button

<

/p

IfmySwitchForfalse, the button is available:

<

p

<

button

Click me!

<

/button

<

/p


ng-show directive

ng-showHides or shows an HTML element.

AngularJS instance

<

div

ng-app=

""

<

p

ng-show=

"true"

I am visible.

<

/p

<

p

ng-show=

"false"

I am invisible.

<

/p

<

/div

Try »

The ng-show directive shows (hides) HTML elements based on the value of ** value**.

You can use an expression to calculate a boolean value (true or false):

AngularJS instance

<

div

ng-app

=

"

"

ng-init

=

"

hour=13

"

<

p

ng-show

=

"

hour > 12

"

I am visible.

</

p

</

div

Try it »

Note In the next chapter, we will introduce more examples of hiding HTML elements by clicking a button.

ng-hide directive

ng-hideThe directive is used to hide or show HTML elements.

AngularJS instance

<

div

ng-app=

""

<

p

ng-hide=

"true"

I am invisible.

<

/p

<

p

ng-hide=

"false"

I am visible.

<

/p

<

/div

Try it »