how to get the attribute value defined in html file of template url in directive

user3824049

below is my directive,

app.directive('search', function($rootScope, $timeout, dynamicValues) {
    return {
        scope: {
            myname: '=',
        },
        restrict: 'AE',
        replace: true,
        templateUrl: 'app/partials/template.html',
    };
}));

and below is my template.html

<input type="text" name="Name" myname = "maho">

so my requirement is I need to get the value of myname attribute i.e "maho" in my directive I tried it using Attr as below

scope.variable = iAttrs.myname;
alert("myname value is..." + scope.variable);

but I am getting undefined value please suggest me how to do this.

Mosho

Try this:

app.directive('search', function() {
    return {
        restrict: 'AE',
        replace: true,
        templateUrl: 'template.html',
        link: function(scope, elm, attrs) {
          scope.variable = attrs.myname;
        }

    };
});

Isolate scopes are for passing variables from parent directives. ngModel binds an element's value to a scope variable.

egghead.io video regarding isolate scopes

docs for ngModel

DEMO

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

get directive attribute defined in HTML in directive controller

From Dev

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

From Dev

How can I get pass value from controller back to directive's template attribute in AngularJS?

From Dev

How can I get pass value from controller back to directive's template attribute in AngularJS?

From Dev

Angular element directive how to get attribute value

From Dev

Passing Attribute Value to Directive Template

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

How do I include HTML from an attribute as a token in a directive template

From Dev

Find value of attribute of html tag that is not defined in any file

From Dev

Find value of attribute of html tag that is not defined in any file

From Dev

How to get and run an attribute of value "{{aaa}}/{{bbb}}" in a directive?

From Dev

How to get and run an attribute of value "{{aaa}}/{{bbb}}" in a directive?

From Dev

AngularJs: Directive with function for template property. How to get scope value?

From Dev

AngularJs: Directive with function for template property. How to get scope value?

From Dev

Angularjs | how to get an attribute value from element in which controller is defined

From Dev

How to get the attribute value which is defined in model using gson

From Dev

How can I pass a template to a directive in an attribute?

From Dev

How to get attribute value from HTML tags

From Dev

How to get an attribute value with lxml on html

From Dev

Using a value instead of variable in the html for a directive attribute

From Dev

Using a value instead of variable in the html for a directive attribute

From Dev

Get value of attribute in Angularjs custom directive

From Dev

Get value of attribute in Angularjs custom directive

From Dev

Angular: get Template URL from parent directive

From Dev

unit testing typescript directive template karma-jasmine, html is not defined

From Dev

Inject User-defined HTML Into Directive's Template

From Dev

Play Framework: How do I get querystring value inside html template file

From Dev

How to set the default value of directive attribute?

Related Related

  1. 1

    get directive attribute defined in HTML in directive controller

  2. 2

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

  3. 3

    How can I get pass value from controller back to directive's template attribute in AngularJS?

  4. 4

    How can I get pass value from controller back to directive's template attribute in AngularJS?

  5. 5

    Angular element directive how to get attribute value

  6. 6

    Passing Attribute Value to Directive Template

  7. 7

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

  8. 8

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

  9. 9

    How do I include HTML from an attribute as a token in a directive template

  10. 10

    Find value of attribute of html tag that is not defined in any file

  11. 11

    Find value of attribute of html tag that is not defined in any file

  12. 12

    How to get and run an attribute of value "{{aaa}}/{{bbb}}" in a directive?

  13. 13

    How to get and run an attribute of value "{{aaa}}/{{bbb}}" in a directive?

  14. 14

    AngularJs: Directive with function for template property. How to get scope value?

  15. 15

    AngularJs: Directive with function for template property. How to get scope value?

  16. 16

    Angularjs | how to get an attribute value from element in which controller is defined

  17. 17

    How to get the attribute value which is defined in model using gson

  18. 18

    How can I pass a template to a directive in an attribute?

  19. 19

    How to get attribute value from HTML tags

  20. 20

    How to get an attribute value with lxml on html

  21. 21

    Using a value instead of variable in the html for a directive attribute

  22. 22

    Using a value instead of variable in the html for a directive attribute

  23. 23

    Get value of attribute in Angularjs custom directive

  24. 24

    Get value of attribute in Angularjs custom directive

  25. 25

    Angular: get Template URL from parent directive

  26. 26

    unit testing typescript directive template karma-jasmine, html is not defined

  27. 27

    Inject User-defined HTML Into Directive's Template

  28. 28

    Play Framework: How do I get querystring value inside html template file

  29. 29

    How to set the default value of directive attribute?

HotTag

Archive