Chapter 2: Basic AngularJS Directives Flashcards
What are modules?
Resubale packages of code
Modules have their own services, controllers, directives and factories.
Can be linked to other modules to complete tasks.
How do you define a module?
angular.module(‘notesapp’, []);
in the ( ) we have the module name in ‘’ and then an array that we can list any dependent modules
The module definition would be script tags as well
What are controllers?
The javascript functions that perform majority of work with the UI
How do I set up a controller
On an element we use the ng-controller directive and give it a name
Then in our script we use the controller function. We pass it two arguments, name of the controller and then the code to execute.
angular.module(‘notesApp’, [])
.controller(‘MainCtrl’, [function() {
// Controller-specific code goes here
console.log(‘MainCtrl has been created’);
}]);
What is controllerAs syntax?
It allows us to specify a nickname for the controller
If we use the this keyword when defining variables in a controller what does it allow us to do?
Write that variable to the page