Angularjs 从角度指令获取数据

Angularjs 从角度指令获取数据,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我创建了一个指令,我称之为my tree,我从视图example tree view.html调用此指令,如下所示: <my-tree ng-model="sampleTreeView.listNoeuds" ... /> 我的问题是如何在sampleTreeView控制器中获取scope.treeActionsResult.createdNode值,因为它是调用我的指令的example tree view.html的控制器。可以通过删除scope属性在指令和控制器之间使用共享作用

我创建了一个指令,我称之为
my tree
,我从视图
example tree view.html
调用此指令,如下所示:

<my-tree ng-model="sampleTreeView.listNoeuds" ... />

我的问题是如何在
sampleTreeView
控制器中获取
scope.treeActionsResult.createdNode
值,因为它是调用我的指令的
example tree view.html
的控制器。

可以通过删除scope属性在指令和控制器之间使用共享作用域

如本例所示:

MyApp.directive('studentDirective', function () {
return {
    template: "{{student.name}} is {{student.age}} years old !!",
        replace: true,
        restrict: 'E',
        controller: function ($scope) {
            console.log($scope);
        }
    }
});
仍然有$scope对象,但在本例中,scope对象与父控制器的scope共享

你可以从下面的链接中了解更多

通过删除scope属性,可以在指令和控制器之间使用共享作用域

如本例所示:

MyApp.directive('studentDirective', function () {
return {
    template: "{{student.name}} is {{student.age}} years old !!",
        replace: true,
        restrict: 'E',
        controller: function ($scope) {
            console.log($scope);
        }
    }
});
仍然有$scope对象,但在本例中,scope对象与父控制器的scope共享

你可以从下面的链接中了解更多

如果不为指令创建隔离作用域,则可以从控制器访问指令作用域值。像吼叫

您的控制器和指令:

app.controller('MainCtrl', function($scope) {
  $scope.value = 1;
});

app.directive('myTree', function() {
  return {
    restrict: 'AE',
    link: function(scope, element, attrs) {
      scope.values = {};
      scope.values.price = 1234;
    }
  };
});
然后在html中使用,如:

<body ng-controller="MainCtrl">
    <p>value {{values.price}}</p>
    <my-tree att="{{attValue}}"></my-tree>
  </body>

值{{values.price}


此处为
值。price
显示在
MainCtrl

中的指令中。如果不为指令创建隔离范围,则可以从控制器访问指令范围值。像吼叫

您的控制器和指令:

app.controller('MainCtrl', function($scope) {
  $scope.value = 1;
});

app.directive('myTree', function() {
  return {
    restrict: 'AE',
    link: function(scope, element, attrs) {
      scope.values = {};
      scope.values.price = 1234;
    }
  };
});
然后在html中使用,如:

<body ng-controller="MainCtrl">
    <p>value {{values.price}}</p>
    <my-tree att="{{attValue}}"></my-tree>
  </body>

值{{values.price}

此处为
value.price
显示在
MainCtrl