Skip to content

Instantly share code, notes, and snippets.

@benmj
Created April 22, 2013 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benmj/5436229 to your computer and use it in GitHub Desktop.
Save benmj/5436229 to your computer and use it in GitHub Desktop.
This works fine in development (Grunt server), but when I deploy it there's a javascript error: "Error: No controller: ngController" However, the controller (passed in as the forth parameter to `link`) works: inside the directive body the functions on the controller can be accessed. I'm happy that it works, but I wonder... why?
angular.module('portal', []).directive('ordersPendingControls', function ($compile) {
return {
scope: {
ordersPendingControls: '='
},
require: "^ngController",
replace: true,
template: '<div>' +
' <button class="btn btn-small" ng-click="editClicked()" ng-disabled="editDisabled" title="Edit this request"><i class="icon-pencil"></i></button>' +
' <button class="btn btn-small" ng-click="deleteClicked()" ng-disabled="deleteDisabled" title="Delete this request"><i class="icon-remove-circle icon-remove"></i></button>' +
'</div>',
link: function (scope, element, attrs, ordersCtrl) {
var row = scope.ordersPendingControls,
isApproved = _.has(row, 'ApprovedDate');
scope.editDisabled = false;
if (isApproved) {
scope.deleteDisabled = true;
}
scope.editClicked = function () {
if (_.has(row, 'OrderChangeID')) { // pending order modification
ordersCtrl.orderModification(row);
} else if (isApproved) { // scheduled order
ordersCtrl.orderModification(row);
} else { // pending order
ordersCtrl.editOrder(row);
}
};
scope.deleteClicked = function () {
if (_.has(row, 'OrderChangeID')) {
ordersCtrl.deleteOrderModification(row);
} else {
ordersCtrl.deleteOrder(row);
}
};
}
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment