2

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?

user2991183
  • 683
  • 1
  • 12
  • 23
  • duplicate of http://stackoverflow.com/questions/13466133/how-can-i-conditionally-require-form-inputs-with-angularjs – frhd Apr 23 '15 at 08:22

2 Answers2

3

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">
thomaux
  • 19,133
  • 10
  • 76
  • 103
1

That would be adding the ng-required tag with a boolean value (angular input doc)

<input id="id" class="form-control" name="thename" type="text" ng-required="required">
frhd
  • 9,396
  • 5
  • 24
  • 41