Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从父指令/angularjs访问输入的ngModel_Angularjs_Angularjs Directive_Typescript - Fatal编程技术网

如何从父指令/angularjs访问输入的ngModel

如何从父指令/angularjs访问输入的ngModel,angularjs,angularjs-directive,typescript,Angularjs,Angularjs Directive,Typescript,我有这个看法 <div my-directive="somevalue"> <input name="myField" ng-model="dataForMyField"> </div> 这是我的指令 app.directive('myDirective', function ($compile) { return { restrict: 'A', template: `<div ng-transclude=""

我有这个看法

  <div my-directive="somevalue">
    <input name="myField" ng-model="dataForMyField">
  </div>

这是我的指令

app.directive('myDirective', function ($compile) {
  return {
    restrict: 'A',
    template: `<div ng-transclude=""></div>
            <div>SomeValue from directive <strong>{{ someReturnedValue }}</strong></div>`,
    transclude: true,
    controller: function($scope, $element, $attrs, $transclude) {

        $scope.someReturnedValue = 'ValueFromDirective';
        console.log('Name of input'); // myField
        $scope.$watch('vm.ngModel', function(newValue, oldValue, scope) {
          console.log('WOW! Input.ngModel changed', newValue); // world in the init
        });

    }
  }
})
app.directive('myDirective',函数($compile){
返回{
限制:“A”,
模板:`
指令{{someReturnedValue}`中的SomeValue,
是的,
控制器:函数($scope、$element、$attrs、$transclude){
$scope.someReturnedValue='ValueFromDirective';
console.log('Name of input');//myField
$scope.$watch('vm.ngModel',函数(newValue、oldValue、scope){
log('WOW!Input.ngModel changed',newValue);//init中的world
});
}
}
})
如何访问输入的模型

--------->这里有一个plkr:

试试这个

<div my-directive="somevalue">
    <input name="myField" ng-model="dataForMyField">
</div>


app.directive('myDirective', function () {
  return {
  scope: {
      dataForMyField: '@dataAttr'
    },
    restrict: 'A',
    template: `<div ng-transclude=""></div>
            <div>SomeValue from directive <strong>{{ someReturnedValue }}</strong></div>`,
    transclude: true,
    controller: function($scope, $element, $attrs, $transclude) {

        $scope.someReturnedValue = 'ValueFromDirective';
        console.log('Name of input'); // myField
    }
  }
})

app.directive('myDirective',function(){
返回{
范围:{
dataForMyField:“@dataAttr”
},
限制:“A”,
模板:`
指令{{someReturnedValue}`中的SomeValue,
是的,
控制器:函数($scope、$element、$attrs、$transclude){
$scope.someReturnedValue='ValueFromDirective';
console.log('Name of input');//myField
}
}
})