0

Now i'm using camelcase directive name, like below

<code-input:text></code-input:text> (or)
<code-input-text></code-text-input>

can i use custom directice name and attribute like this,

<code-input:text dirType="text" labelHead="Code" dirName="Code" dirId="code" dirClass="form-control" dirModel="taskCreateForm.code" section-class="col col-3 required"></code-input:text>

if i give like this means , then doesn't render template from directive.because of, i have set every attribute for this is dynamically.

scope : {
            dirName : '@',
            dirType : '@',
            dirModel : '=',
            labelHead : '@',
            sectionClass : '@',
        },
template : [
                   '<section class="{{sectionClass}}">',
                   '<label class="label">{{labelHead}}</label>',
                   '<label class="input">',
                   '<input type="{{dirType}}" name="{{dirName}}" id="{{dirId}}" class="{{dirClass}}" ng-model="dirModel">',
                   '</label>',
                   '</section>'
                   ].join(''),

can anyone give me guidance..is't possible or any issue has occurred because of this.else it's not standard way?

1
  • another one question..what about custom directive attribute names..shall i give attribute name like dirName instead of dir-name in custom directive tag.? Commented Sep 28, 2015 at 13:23

2 Answers 2

1

From https://docs.angularjs.org/guide/directive#normalization:

The normalization process is as follows:

  1. Strip x- and data- from the front of the element/attributes.
  2. Convert the :, -, or _-delimited name to camelCase.

That is to say, code-input-text and codeInputText are equivalent and match the codeInputText directive.

Sign up to request clarification or add additional context in comments.

4 Comments

what about custom directive attribute names..shall i give attribute name like dirName instead of dir-name in custom directive tag.?
@udays The directive name should be in camelCase, but the element/attribute name can be in the case you want, as long as it is normalized to the directive name. Angular recommends using a dash-delimited format though, i.e. code-input-text.
ya i know that bro..but i have doubt..i have try this to bind attribute data like <code-input-text dirData="something"></code-input-text> instead of <code-input-text dir-data="something"></code-input-text>..but it not working.
@udays Please update your question with this code as well (+ the way dir-data is read), and explain what it is not working.
0

If you created custom directive like

<codeInputText></codeInputText>

You have to use

<code-input-text></code-text-input>

it is better understanding of directive.

2 Comments

Because whole directive name itself indicator not part of directive.
if i use <codeInputText></codeInputText> like this, it will work or not?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.