Access AngularJs Direktivenvariable innerhalb des Controllers
Ich bin ein bisschen neu in Angularjs. Was ich will, ist Zugang " $ scope.myVar "Variable innerhalb von ' myController 'controller. Es wäre eine große Hilfe, wenn Sie eine Lösung anbieten könnten.
angular.module('myDirective', [])
.controller('myController', ['$scope', function ($scope) {
}])
.directive('myDirective', function () {
return {
scope: {
myVar: '='
},
controller: function ($scope) {
$scope.myVar = 'xyz';
alert($scope.myVar);
}
};
});
<html lang="en-US">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script type="text/javascript" src="newjavascript.js"></script>
<body ng-app="myDirective">
<div ng-controller="myController">
<my-directive></my-directive>>
</div>
</body>
</html>