You now have
- {{thing}}
installed.
Enjoy coding! - Yeoman We can package them up into a JavaScript file and let the JavaScript stand alone, like so: angular.module('myApp') run(['$templateCache', function($templateCache) { $templateCache.put('views/main.html', "\n" + " 'Allo, 'Allo!\n" + "You now have
\n" + "- \n" + "
- {{thing}} \n" + "
installed.
\n" + " Enjoy coding! - Yeoman\n" + "\n" ); }]); To set that up, we need to modify our Gruntfile.js to include a new task definition using a new npm package grunt-angular-templates First, we install the package: $ npm install save-dev grunt-angular-templates Next, we modify our Gruntfile.js to include the ngtemplates task Next Steps 595 // } }, ngtemplates: { myappApp: { cwd: '', src: 'views/**/*.html', dest: '/scripts/templates.js' } }, // Put files not handled in other tasks here copy: { // This modification simply creates a new file in our app directory that will contain the template files loaded as JavaScript We need to make sure that this task runs in the build process Luckily, it’s easy to append tasks to the build process We simply find the line: grunt.registerTask('build', [ and make sure we’ve added ngTemplates into the array of tasks after the concat task: grunt.registerTask('build', [ // 'concat', // 'cssmin', 'ngtemplates', 'uglify', 'rev', 'usemin' ]); Lastly, we need to ensure that we include the templates.js file in our app/index.html file after we’ve included the scripts/app.js file: Now, when we build our app, our templates will come packaged along with the rest of the application Next Steps 596 Note that when we’re developing our application, if the template isn’t found in the cache, it loads from the server automatically, so we can safely delete the app/scripts/template.js file if we need to at some point during our development process If this file exists, then the views that it caches won’t be reloaded; it will think it has the template available ... ⁵http:/ /angularjs. org ⁶http://google.com Introduction ng- book: The Complete Guide to AngularJS gives you the cutting-edge tools you need to get up and running on AngularJS and creating impressive... inside of the DOM element upon which it is declared belong to the Angular app, declaring the ng- controller attribute on a DOM element says that all of the elements inside of it belong to the controller... events to other controllers and parts of the application It is ideal to contain the application logic in a controller and the working data on the scope of the controller The $scope View of the World