How to conditionally apply attribute in angularJS directive?

user2991183

In html:

<cms-text required="false" id="product_name" thename="product_name"></cms-text>

In cmsText.js

angular.module('cmsText',[]).directive('cmsText', function(){
'use strict';

    return {
        restrict: 'EA',
        scope: {
            thename:'=',
            required:'=',
            id:'='

        },
        replace:true,    
        templateUrl: 'cms-text/cmsText.html',
    };

});

In cmsText.html

<input id="id" class="form-control" name="thename" type="text" required>

I want the "required" word in input tag shows only when it is set to true and the word disappear when it is set to false. Anyone could help?

thomaux

Use ngRequired to control the required attribute in Angular.

Update your template to

<input id="id" class="form-control" name="thename" type="text" ng-required="required">

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to conditionally apply attribute in angularJS directive?

From Dev

How to apply directive conditionally in AngularJS?

From Dev

AngularJS - Use attribute directive conditionally

From Dev

AngularJs apply custom directive to HTML conditionally

From Java

Apply a directive conditionally

From Dev

How to bind an attribute in a AngularJS directive?

From Dev

AngularJS: How to monitor an attribute in a directive?

From Dev

AngularJS conditionally add directive

From Dev

AngularJS - Apply required attribute conditionally based on radio button value

From Dev

AngularJS: How to conditionally apply view animations?

From Dev

How to create a Attribute Directive to insert another attribute directive in a element in AngularJS

From Dev

How to apply Emojis to Angularjs directive list?

From Dev

How do you 'require' an attribute on an angularjs directive?

From Dev

AngularJS: How to set an attribute to a custom directive

From Dev

Angularjs directive: how to pass an array via attribute?

From Dev

AngularJs: How to get the attribute value of a attribute type directive

From Dev

AngularJs: How to get the attribute value of a attribute type directive

From Dev

Attribute directive in AngularJS

From Java

How do I conditionally apply CSS styles in AngularJS?

From Dev

Conditionally wrap a directive with another, based on scope attribute

From Dev

Conditionally add/remove attribute in angularjs

From Dev

How can i apply a draggable directive to bootstrap modal using angularJS?

From Dev

How can I apply a class from one directive to another in angularjs?

From Dev

How to apply animation conditionally?

From Dev

AngularJS: Apply another directive in my directive

From Dev

Angularjs - how do i access directive attribute in controller

From Dev

How to get attribute value in template in angularjs custom directive?

From Dev

AngularJS: how do I code an element directive with optional attribute parameters?

From Dev

AngularJS: How to access input[date] min attribute within custom directive?

Related Related

  1. 1

    How to conditionally apply attribute in angularJS directive?

  2. 2

    How to apply directive conditionally in AngularJS?

  3. 3

    AngularJS - Use attribute directive conditionally

  4. 4

    AngularJs apply custom directive to HTML conditionally

  5. 5

    Apply a directive conditionally

  6. 6

    How to bind an attribute in a AngularJS directive?

  7. 7

    AngularJS: How to monitor an attribute in a directive?

  8. 8

    AngularJS conditionally add directive

  9. 9

    AngularJS - Apply required attribute conditionally based on radio button value

  10. 10

    AngularJS: How to conditionally apply view animations?

  11. 11

    How to create a Attribute Directive to insert another attribute directive in a element in AngularJS

  12. 12

    How to apply Emojis to Angularjs directive list?

  13. 13

    How do you 'require' an attribute on an angularjs directive?

  14. 14

    AngularJS: How to set an attribute to a custom directive

  15. 15

    Angularjs directive: how to pass an array via attribute?

  16. 16

    AngularJs: How to get the attribute value of a attribute type directive

  17. 17

    AngularJs: How to get the attribute value of a attribute type directive

  18. 18

    Attribute directive in AngularJS

  19. 19

    How do I conditionally apply CSS styles in AngularJS?

  20. 20

    Conditionally wrap a directive with another, based on scope attribute

  21. 21

    Conditionally add/remove attribute in angularjs

  22. 22

    How can i apply a draggable directive to bootstrap modal using angularJS?

  23. 23

    How can I apply a class from one directive to another in angularjs?

  24. 24

    How to apply animation conditionally?

  25. 25

    AngularJS: Apply another directive in my directive

  26. 26

    Angularjs - how do i access directive attribute in controller

  27. 27

    How to get attribute value in template in angularjs custom directive?

  28. 28

    AngularJS: how do I code an element directive with optional attribute parameters?

  29. 29

    AngularJS: How to access input[date] min attribute within custom directive?

HotTag

Archive