AngularJS Richtlinie Rückruf

Ich möchte senden Sie ein Anruf zurück in eine Richtlinie über einen parameter auf den tag, und rufen Sie dann diese Methode, wenn innerhalb der entsprechenden Richtlinie. Zum Beispiel, wenn ein button geklickt wurde, rufen Sie eine Methode auf der parent-controller.

Habe ich eine einfache plunker es nicht funktioniert

html-Datei:

<body ng-controller="ParentController">
    <h1> Method Arguments </h1>
    <h3> open console to view output</h3>
    <hello-world onLoadCallback="myCallback(arg1)"></hello-world>
</body>

javascript-Datei:

var app = angular.module("app",[]);

function ParentController($scope) {
  $scope.myCallback = function(var1){
    console.log("myCallback", var1);
  }
}
app.directive('helloWorld', function() {
  return {
      restrict: 'AE',
      template: '<h3>Hello World!!</h3>',
      scope:{
            onLoadCallback: '&'
        },
        link: function(scope, element, attrs, dateTimeController) {
            console.log('linked directive, not calling callback')
            scope.onLoadCallback('wtf');

      }
  };
});

InformationsquelleAutor nakkor | 2014-07-08

Schreibe einen Kommentar