In this post I will exaplin how to create simple Angular JS application. This will continue with the code written in my last post.
In Scripts folder create a folder called app. In that folder create AngularJS main module. By convention, main module is define in app.js file.
Use IIFE Javascript pattern for define the main module.
Add index.html file into wwwroot. Add AngularJS reference. Also you need to add app.js reference. This is a minified javascript file.
Our target is to show a student list. Therefore, add students folder into app folder. Then create studentListController.js file like below.
We can write an Angular service to load students from Web API. First create services module like below.
Then create studentResource.js file in resource folder. The code should be like below. In here I used built in Angular service for call a web service. This is a angular factory which create resource objects which only works with REST services.
Now we need to add ngResource module to common.services as a dependency.
ngResource module is not provided with angular. So we need to add javascript reference as below.
Let's use the data access component in studentListController. $scope is an object that refers to the application model. We must add dependencies correctly.
In the main module, change code like below for dependency injection.
Index.html file content should change like below. There are several classes added which are from Botstrap.
To have bootstrap functionality, add JS and CSS file references like below.
Run the project, and response would be like;
Sunday, April 12, 2015
Friday, March 27, 2015
Using Grunt in ASP.net 5 project
We will continue this with the code which I have done in my last post.
What is Grunt? Grunt is an open-source tool that you can use to build all of the frontend resources for your project.
In this demo, I will mainly use Grunt for JavaScript minification.
There are three types of Package Managers in Visual Studio 2015.
First we will define Grunt package in NPM. For that we need to add NPM file like below.
Change the content of package.json file like below. It will add, NPM packages into the project.
Add Grunt.js file and change content of that file for JavaScript minification process. This code will minify all javscript files in Scripts folder and create app.js file in wwwroot. Uglify combines JavaScript files according to the order they have defined in Grunt Configuration.
Add Scripts folder and add a javascript file into that folder. Open Task Runner in Visual Studio.
Run Uglify command. This will create app.js minified file in wwwroot folder.
It's easier if you bind the Uglify command to automatically run in After Build.
What is Grunt? Grunt is an open-source tool that you can use to build all of the frontend resources for your project.
In this demo, I will mainly use Grunt for JavaScript minification.
There are three types of Package Managers in Visual Studio 2015.
- Nuget
- NPM(Node Package Manager)
- Bower
First we will define Grunt package in NPM. For that we need to add NPM file like below.
Change the content of package.json file like below. It will add, NPM packages into the project.
Add Grunt.js file and change content of that file for JavaScript minification process. This code will minify all javscript files in Scripts folder and create app.js file in wwwroot. Uglify combines JavaScript files according to the order they have defined in Grunt Configuration.
Add Scripts folder and add a javascript file into that folder. Open Task Runner in Visual Studio.
Run Uglify command. This will create app.js minified file in wwwroot folder.
It's easier if you bind the Uglify command to automatically run in After Build.
Thursday, March 26, 2015
Using Web API in ASP.net 5
In my last post I created a Web Project using ASP.net 5. Now we will create some web api controllers.
First, add ASP.net MVC nuget package to the project.
Then change the Startup.cs class like below.
When you run the application, the browser must open following page, which means your IIS works correctly.
In ASP.net 5, there are two primary concepts.
First, add ASP.net MVC nuget package to the project.
Then change the Startup.cs class like below.
When you run the application, the browser must open following page, which means your IIS works correctly.
In ASP.net 5, there are two primary concepts.
- Middleware
- Services
Change the Startup class like below. Above mentioned middleware and Service codes are applied from Startup class. This code has configured to use DbContext using DI pattern.
If you have data in your database, then you will be able to see an output like below.
Assume, there was an exception occurred. Change the web api controller code like below.
Change the Startup.cs file content.
When you run the project, you will see a beautiful error handling page which contains lots of details.
Assume, there was an exception occurred. Change the web api controller code like below.
Change the Startup.cs file content.
When you run the project, you will see a beautiful error handling page which contains lots of details.
Subscribe to:
Posts (Atom)






.png)
.png)