If u using Controller & controlleras in Directive, then the link () ' s 4th param ' controller ' would refer to the controller u defined before.
functionMessagecontroller () {varVM = This; Vm.message= "Hello"; }functiongreeting () {functionlink (scope, element, Attrs, ctrl) {Ctrl.message= Ctrl.message + "+Scope.name; } return{controller:' Messagecontroller ', Controlleras:' VMS ', Link:link, scope: {name:‘@‘}, Template:' };} Angular.module (' App ', []). Directive (' Greeting ', greeting). Controller (' Messagecontroller ', messagecontroller);
<!DOCTYPE HTML><HTML><Head><Scriptsrc= "Https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></Script> <MetaCharSet= "Utf-8"> <title>JS Bin</title></Head><BodyNg-app= "App"><Greetingname= "Zhentian"></Greeting></Body></HTML>
[AngularJS] Accessing the View-model Inside the link () when Using Controlleras