1
<section id="content" ng-controller="ReservationController as resvnCtrl" >
<form role="form" name="resvnCtrl.form">
<div data-date-picker>
</div>
</form>
</section>
指令
var eateryDirectives=angular.module('eateryDirectives',['eateryControllers']);
eateryDirectives
.directive('datePicker',function(){
var directive={
require:'^resvnCtrl',
link:function(scope,ele,attrs,cntrl){
console.log(cntrl);
}
};
return directive;
});
我控制器找不到錯誤。順便說一句,控制器和diretcive在不同的模塊。這很重要嗎?如何從指令訪問該控制器?
ReservationController在eateryControllers模塊 –
很難說你應該怎麼做,而不知道你的總體目標是什麼,但是你的問題是你試圖以一種無法使用的方式使用指令的'require'。 http://stackoverflow.com/questions/15672709/how-to-require-a-controller-in-an-angularjs-directive – m59
我做了同樣的鏈接 –