Created
April 22, 2013 15:52
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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