Write an Angular app with speedy Angular generator
How did dev Angular doctors start? I had to:
- Angular download
- Add index.html
- Create app.js file , add index.html
- angular.module ('myApp', ['bla', 'balo']);
- Download more packages , then inject
- Create file controller , view , service , filter and so on
So many ha, so I still do so until one day, I work together as a project, PM set up the angular generator and hand it to the team dev. I was stupid to open the bower.json file to Google search each one and then add index.html . It was only after being asked to teach, how could it be. After knowing the Angular genarator, the job is significantly faster, without having to search for packages and add more.
So, I wrote this article to guide Angular generator users to dev Angular quickly – (feeling like Flash)
Introduce
Yeoman.io
What's Yeoman?
Yeoman helps you to kickstart new projects, prescribing the best practices and tools to help you stay productive.
Http://yeoman.io homepage
This is a tool that helps dev can find on the "genarator" to use for his project or if there is a leader, he can write generator to share for the community to get fame points. The reason why I introduced this guy, is talking about the Angular generator . In fact, this guy is the guy of the many generators, Angular generator that I mentioned above is just a grandchild. If you want to use the Angular generator , you must have a yeoman in the machine.
Yeoman installation
1 | npm install -g yo |
Accomplished! So there is Yeoman.
AngularJS generator
The main character is here. Ten.
Github https://github.com/yeoman/generator-angular
Just install it
1 | npm install -g grunt-cli bower yo generator-angular generator |
So there is an Angular generator in the machine. War time.
Using
Begin
Open CMDER and fight.
Create a folder for the project and then move to the folder
1 | mkdir my-new-project && cd my-new-project |
Generate angular out.
1 | yo angular [app-name] |
He will ask you some options. Move up and down and press Space to select / deselect and then Enter to go to the next step.
Okey is done, fast. Now run the test
1 | grunt serve |
It will automatically open the browser to access the local address that is running the angular app that you are devging. Not yet.
Interface when testing
And yet, Angular generator also supports you to create controller file , view , service , … and then add it to index.html too . Your job is code on the generated files.
Create route
Generate the controller file , view , and config route to connect to the newly created wins.
1 | yo angular: route myroute |
Create controller
The following command will create a flash controller
1 | yo angular: controller flash |
Directive
1 | yo angular: myDirective directive |
Filter
1 | yo angular: myFilter filter |
View
1 | yo angular: view flash |
Service
1 | yo angular: service myService |
Also if the code is in CoffeeScript or TypeScript
Add –coffee or –typescript at the end of the command.
For example.
1 | yo angular: controller quicksilver --coffee |
The most important command
1 | grunt build |
This command will build the project where the product components. That is, it will collect all, minimize code, optimize it for the most compact. When you run the above command, all of your product code is in the dist folder .
Install additional packages.
By default Angular generator uses Bower and NPM .
NPM can completely replace the bower but I recommend that you use bower . NPM is for nodejs (server side) and bower for client side. Maybe .
For example, if you want to install Package loading bar like the previous one, I recommend it .
- Go to Github of Package and say https://github.com/chieffancypants/angular-loading-bar
- See there line it only for installation bower install angular-loading-bar
- Copy put in cmder, ENTERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Finished, so have a delicious, self-included package on index.html for you guys. Your task is to inject into angular in app.js file only.
Bower contains countless packages for you to research, explore, see which one is more and more, make sure after a while your app is like … fair
End
With the society becoming more progressive and civilized, the code also becomes easier, supporting the teeth for the doctors. Your job is to upload it to Stackoverflow copy and finish. Ez life.
The fastest way to code is to distort the code at all!
ITZone via cuthanh