双向绑定-从隔离范围更新控制器范围

时间:2019-06-07 05:19:17

标签: javascript angularjs angularjs-directive angular-ui-bootstrap

创建了一个包含日期选择器的指令。用户输入时,我正在创建一个验证码。

如何将datepicker的值从隔离范围更新为控制器范围?

朋克车示例

https://plnkr.co/edit/f8s5KOi62xsEVj6S7ucx?p=preview

app.directive('myDatepicker', function() {
  return {
    restrict: 'E'
    scope: {
      ngModel: "=",
     },
  require: 'ngModel',
      link: function(scope, element) {

         scope.keyUpValidate = function(val, event){

           var newVal = val || event.target.value;
          console.log(newVal)
           // change value of selected on keyup event
           // logic here

          // how to update the ngModel?
          scope.ngModel = newVal; // doesnt work 

         }
     }
 };
});

0 个答案:

没有答案