0

I'm not getting how to over come the following situation, I have a directive with two scope passed from parent as "=" denoting the model binding say attr1 and attr2 are those values.

Inside directive I have used both in the interpolation {{attr1}} and {{attr2}}, Also I have used it inside input type text and email as models.

When I change the value of attr1 from textbox the value gets reflected in the interpolation {{attr1}}, but the change in attr2 textbox is not reflected in the interpolation {{attr2}} , although it gets binded when an valid email id is entered, but i need to show the email when its being typed.

Is there any work around for this ?

How can I do it ?

The fiddle is here.

app.directive("myDirective", function(){

return {
    restrict: "EA",
    //replace:true,
    //transclude:true,
    scope: {
        attr1: "=",
        attr2: "="
    },
    template: [
        "<div>attr1 : {{attr1}}</div>",
        "<div>attr2 : {{attr2}}</div>",
        "attr1 : <input type='text' ng-model='attr1' /><br/>",
        "attr2 : <input type='email' ng-model='attr2' /><br/>",
        ].join(""),

};   

Thanks,

Vinod Louis

4

1 回答 1

0

先生,这是 html 5 电子邮件验证的问题,除非您输入正确的电子邮件格式,否则您将不会显示键入的字段,因为 html 5 类型的电子邮件具有类似这样的验证格式 a@bc。还有一件事是在您的代码中您编写了 my-directive,在指令中您编写了 myDirective。我已经解决了这个问题,请尝试在您的电子邮件字段中输入任何有效的电子邮件格式。实际上 ng-biding 正在发生,但是当您正确输入电子邮件格式时,文本将可见。 小提琴

这是我的代码html

<div ng-app="app">
 <name attr1="Sudarshan"  attr2="sud@gmail.com"></name>
</div>

ng代码

var app = angular.module("app", []);
app.directive("name", function(){
     return {
        restrict: "E",
        link:function(scope,e,a){
            scope.att1=a.attr1;
            scope.att2=a.attr2;
         },
       template: 
            ["<div>attr1 : {{att1}}</div>",
            "<div>attr2 : {{att2}}</div>",
            "attr1 : <input type='text' ng-model='att1' /><br/>",
            "attr2 : <input type='email' ng-model='att2' /><br/>"].join(""),
 };
});
于 2014-08-19T08:50:50.433 回答