
Let's Create the Front End Views:
- Create the File Structure of the Contact
Create the contact folder and under it, create controller and html folders. Follow the folder structure above.
- Create the contactController.js under the controller folder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
contactApp.controller('contactController', ['$scope', function categoryController($scope) { $scope.contacts =[ { firstName: 'John', lastName: 'Parson', email: 'parson@gmail.com', mobile: '233-900-2933' }, { firstName: 'Joe', lastName: 'Paris', email: 'paris@gmail.com', mobile: '233-900-2933' }, { firstName: 'Donna', lastName: 'Lim', email: 'lim@gmail.com', mobile: '552-221-2222' } ]; $scope.contact = {}; }]); - Create the contactsList.html under the html folder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
<div class="panel panel-primary"> <div class="panel-heading">My Contacts</div> <div class="panel-body"> <div class="col-md-6"> <a class="btn btn-primary" href="#/mycontacts/newcontact"><i class="glyphicon glyphicon-file"></i> New</a> </div> <div class="col-xs-10 col-lg-6 col-md-6"> <div class="input-group"> <input type="text" id="searchText" class="form-control pull-right" placeholder="Search for..." ng-model="search_txt"> <span class="input-group-btn"> <button class="btn btn-default" type="button"> <i class="text-muted glyphicon glyphicon-search"></i> </button> </span> </div><!-- /input-group --> </div><!-- /.col-lg-6 --> <div class="table table-responsive"> <table class="table table-striped"> <thead> <tr> <td>Last Name</td> <td>First Name</td> <td>Email</td> <td>Mobile</td> </tr> </thead> <tbody> <tr ng-repeat="contact in contacts | filter:search_txt "> <td>{{contact.lastName}}</td> <td>{{contact.firstName}}</td> <td>{{contact.email}}</td> <td>{{contact.mobile}}</td> </tr> </tbody> </table> </div> </div> </div> - Create the contactForm.html under the html folder.
This will be the new contact view (The C of the CRUD)This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters<div class="panel panel-primary"> <div class="panel-heading">New Contact</div> <div class="panel-body"> <form class="form-horizontal" role="form" id="contactForm" name="contactForm"> <div class="form-group"> <label for="firstName" class="col-sm-3 control-label">First Name</label> <div class="col-sm-6"> <input type="text" id="firstName" name="firstName" class="form-control" ng-model="contact.firstName" ng-required="true" placeholder="First Name" /> </div> </div> <div class="form-group"> <label for="lastName" class="col-sm-3 control-label">Last Name</label> <div class="col-sm-6"> <input type="text" id="lastName" name="lastName" class="form-control" ng-model="contact.lastName" ng-required="true" placeholder="Last name" /> </div> </div> <div class="form-group"> <label for="email" class="col-sm-3 control-label">Email</label> <div class="col-sm-6"> <input type="email" id="email" name="email" class="form-control" ng-model="contact.email" ng-required="true" placeholder="email" /> </div> </div> <div class="form-group"> <label for="mobile" class="col-sm-3 control-label">Mobile #</label> <div class="col-sm-6"> <input type="text" id="mobile" name="mobile" class="form-control" ng-model="contact.mobile" placeholder="Mobile #" /> </div> </div> <div class="form-group"> <div class="col-md-3 col-sm-3 col-sm-offset-3 col-md-offset-3"> <input type="button" id="cancelSave" name="cancelSave" value="Cancel" class="btn btn-warning" /> <input type="submit" id="submitForm" name="submitForm" value="Save" class="btn btn-primary" /> </div> </div> </form> </div> </div> - Update the routes.
Open the _Layout.cshtml and insert the My Contacts link.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters<div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li><a href="#/">Home</a></li> <li><a href="#/mycontacts">My Contacts</a></li> <li><a href="#/about">about</a></li> </ul> </div> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characterscontactApp.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/', { templateUrl: "/app/Home/home.html" }), $routeProvider.when('/about', { templateUrl: "app/Home/about.html" }), $routeProvider.when('/mycontacts', { templateUrl: "app/contact/html/contactsList.html", controller: "contactController" }), $routeProvider.when('/mycontacts/newcontact', { templateUrl: "app/contact/html/contactForm.html" }), $routeProvider.otherwise({ redirectTo: '/' }); }]); - Include the contactController.js in the BundleConfig.cs.
Open the BundleConfig.cs. Add the ~/App/contact/controller/contactController.js in the ~/bundles/angularApp. See the code snippet below.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersbundles.Add(new ScriptBundle("~/bundles/angularApp").Include( "~/Scripts/Angular1.3.5/angular.js", "~/Scripts/Angular1.3.5/angular-route.js", "~/Scripts/Angular1.3.5/angular-resource.js", "~/App/contactApp.js", "~/App/clientRoute.js", "~/App/contact/controller/contactController.js" )); - Compile the application. You should navigate at the My Contacts menu. The 2 buttons at the New Contact is not functioning as of now. We will handle that our next series.
Next: Part 3 : Creating the Back End Using ASP.NET MVC
6 comments
I found a typo which causes it to not find the new page. remove the s in contactsList.html as noted below
Reply$routeProvider.when('/mycontacts', {
templateUrl: "app/contact/html/contactsList.html",
controller: "contactController"
}),
Oh! My mistake! Thank you for notifying me. I appreciate it very much.
ReplyIt was a typo error at Step # 3. It's suppost to be contactsList.html (not contactList). I have already corrected it.
You're suggestion is correct(since you followed step # 3).
Once again my apologies and most of all thank you for viewing my blog.
Great Article on MVC5
ReplyMVC 5 Training
ReplyThank you for using my Guide and if it work for you that makes me happy.
Offshore Angularjs Developers
ReplyI have read your blog its very attractive and impressive. I like it your blog.
Angularjs Online Training Angularjs Training Angularjs Training Angularjs Training in Chennai Angularjs Training in Chennai Angularjs Course Angularjs Course Angular 2 Training in Chennai