Javascript AngularJs将指令参数绑定到mdDialog';s形

Javascript AngularJs将指令参数绑定到mdDialog';s形,javascript,angularjs,angular-material,Javascript,Angularjs,Angular Material,嗨,伙计们,我有一个非常复杂的问题 我已经创建了一个可重用指令,现在我想获取用户的参数值,并将其绑定到指令内的表单 在用户端,他们可以通过以下方式调用指令: <test-app></test-app> 在FormButton.html中: <md-button ng-click="main.openDialog()"> </md-button> 在dialog.html中: <md-dialog> <form>

嗨,伙计们,我有一个非常复杂的问题

我已经创建了一个可重用指令,现在我想获取用户的参数值,并将其绑定到指令内的表单

用户端,他们可以通过以下方式调用指令:

<test-app></test-app>
在FormButton.html中:

<md-button ng-click="main.openDialog()"> </md-button>

在dialog.html中:

<md-dialog>
   <form>
      etc , etc

     <input type="email" name="email" placeholder="Email" data-ng-model="userEmail">
      etc , etc
   </form>
</md-dialog>

等等等等
等等等等
问题:我需要从用户端传入userEmail值,并将其绑定到表单,这样当用户打开表单时,该值就存在了

我认为由于templateUrl,绑定模型的常规方法不起作用

我所尝试的: 1) 我尝试绑定ng模型,但表单位于另一个页面中,因此无法读取值

2) 我想将指令中的值传递给控制器,我在网上进行了研究,但没有找到解决这个问题的可行方案

有人能帮忙解决这个问题吗


<test-app email="test@hotmail.com"></test-app> 
您正在“email”变量中传递值。但您没有在指令范围内映射此变量

试试这个

<test-app userEmail="test@hotmail.com"></test-app> 

看看$mdDialog api,尤其是
locals
选项

局部变量-{object=}:包含键/值对的对象。钥匙 将用作要注入控制器的值的名称。对于 例如

在html中:

<test-app user-email="{{ main.userEmail }} "></test-app>
在dialog.html中:

<md-dialog>
  <form>
   <!-- etc , etc-->

    <input type="email" name="email" placeholder="Email" data-ng-model="dialog.userEmail">


在指令中使用
bindToController:true
ng model=“user.email”
应该是
userEmail
@Claies,但它对output@PankajParkar改变。但这似乎并没有影响到它上面的打字错误对不起。我在我的网站上把它作为用户电子邮件。还有什么我能解决的办法吗?这很有效!但是,我可以问一下如何将参数值从指令传递给控制器,以便我可以使用双向绑定将其绑定到此.userEmail??即使用
userEmail:'='
而不是
userEmail:'@'
。这也允许您放弃使用{{}的必要性,在
中,我使用了userEmail:'='并得到了一个parse:lexerr错误。还有其他方法吗?忘记移除{{}括号了,对不起。但它仍然不起作用,真令人担忧!已经解决了!如果你不介意的话,你能帮我回答我的其他问题吗!
this.userEmail = 'someone@neeae.com';
function openDialog(){
  $mdDialog.show({
    controller: 'DialogCtrl as dialog',
    templateUrl: 'dialog.html',
    locals: {
      email: this.userEmail  // `this` is the main controller (parent).
    }
  });
}
<test-app user-email="{{ main.userEmail }} "></test-app>
angular.module('TestModule').controller('DialogCtrl', ['$mdDialog', '$scope', 'email', function($mdDialog, $scope, email) {
  // Here you can use the user's email  
  this.userEmail = email;
  function submit() {
    //etc etc ..
  }
}]);
<md-dialog>
  <form>
   <!-- etc , etc-->

    <input type="email" name="email" placeholder="Email" data-ng-model="dialog.userEmail">