18.05.2016 Views

Mittwoch, 18. Mai, 2016

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Finishing Angular TODO application and deploying to production 103<br />

1 //in the .js file:<br />

2 angular.module('app')<br />

3 .directive('alertMessage', function() {<br />

4 return function(scope, element, attrs) {<br />

5 element.text(attrs.alertMessage);<br />

6 };<br />

7 });<br />

8<br />

9 //in the HTML<br />

10 The message is .<br />

There are actually whole books written on this subject like this¹⁷⁵ or this¹⁷⁶ and we won’t go any<br />

further with this (nor use it to make our own custom directives ), but for starters if you want<br />

to get more into all the directive awesomeness here’s a good official tutorial¹⁷⁷ from Angular team.<br />

Folder structure<br />

We spoke already about how folder structure is important when the application gets big, and I’ve<br />

noted how nice it is when you run into a well known environment, so in that case we’ll take the<br />

word of experienced contributors at MEAN.js and do it their way¹⁷⁸; create a folder named example<br />

in your public folder. In it create a file example.client.module.js and paste the following code in it:<br />

1 angular.module('example', []);<br />

In order to be able to use this module, you need to include the following script tag in the index.ejs<br />

file, just above the inclusion of the application.js file:<br />

1 <br />

Additionally, now you’re going to add your first dependency. Go to the main application.js file and<br />

make the corresponding line look like this:<br />

1 var app = angular.module(appName, ['example']);<br />

Namely, you’ve added the example module dependency to the main application module. Shortly<br />

now, in the Controllers & $scope section I’ll explain why is this dependency thingy so cool.<br />

¹⁷⁵http://amzn.to/1MtHdn0<br />

¹⁷⁶http://amzn.to/1MtHnLi<br />

¹⁷⁷https://docs.angularjs.org/guide/directive<br />

¹⁷⁸https://www.youtube.com/watch?v=LZA36YIu2yU

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!