AngularJS - Directives vs Controllers

后端 未结 3 1671
遇见更好的自我
遇见更好的自我 2020-12-01 04:07

I am trying to create my first app using AngularJS. However, I\'m a bit confused if I need to use directives for my particular case.

I have a simple Map page, where

3条回答
  •  春和景丽
    2020-12-01 05:06

    Here's a brief stand-alone answer, with links to official docs for further info (definition of "services" added for good measure):

    http://docs.angularjs.org/guide/controller

    In AngularJS, a controller is a JavaScript constructor function that is used to augment the AngularJS scope.

    When a controller is attached to the DOM via the ng-controller directive, AngularJS will instantiate a new controller object, using the specified controller's constructor function. A new child scope will be available as an injectable parameter to the controller's constructor function as $scope.

    http://docs.angularjs.org/guide/directive

    At a high level, directives are markers on a DOM element (such as an attribute, element name, or CSS class) that tell AngularJS's HTML compiler ($compile) to attach a specified behavior to that DOM element or even to transform the DOM element and its children.

    http://docs.angularjs.org/guide/services

    AngularJS services are substitutable objects that are wired together using dependency injection (DI). You can use services to organize and share code across your app.

提交回复
热议问题