Search code examples
angularjsangularjs-scopeangular-directive

Angular directive without scope defined


I would like to know what it mean when directive definition have no scope:, and also what would be equivalent if I where to add scope:.

Like this example:

.directive('myCustomer', function() {
  return {
    template: 'Name: {{customer.name}} Address: {{customer.address}}'
  };
});

Solution

  • Short answer: It means that it that the directive inherits the scope of the controller and doesn't have its own 'isolate scope'.

    Not having an isolate scope means more coupling with the controller and less reusability (as it depends on the controller's scope).