01. Install angular CLI npm -g install @angular/cli npm install -g @angular/cli@latest 02. Check angular Details…
Category: JAVASCRIPT
All my javascript works
Generic CRUD with andgularJs dependency injection
#Controller public class Result { public int Id { get; set; } public string value Details…
Dynamic from upload with angular js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
@*@model ERPSales.Web.Areas.Settings.ViewModels.CategoryViewModel*@ @{ ViewBag.Title = "Create Category"; } <div ng-app="createCatgeoryApp" ng-controller="createCategoryController"> <div class="panel panel-info"> <div class="panel-heading clearfix"> Catgeory page </div> <div class="panel-body"> <!-- Button trigger modal --> <button class="btn btn-primary" data-toggle="modal" data-target="#myModal" data-backdrop="static" data-keyboard="false"> Add Category </button> </div> </div> <div> <table class="table table-bordered"> <tr> <th style="width: 20%"> Name </th> <th> Description </th> <th> Action </th> </tr> <tr ng-repeat="cat in categories"> <td> {{cat.Name}} </td> <td> {{cat.Description}} </td> <td> <span ng-click="editCategory(cat)" class="btn btn-success" data-toggle="modal" data-target="#myModal" data-backdrop="static" data-keyboard="false">Edit</span> <span ng-click="deleteCategory(cat)" class="btn btn-danger">Delete</span> </td> </tr> </table> </div> <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> × </button> <h4 class="modal-title" id="myModalLabel"> This Modal title </h4> </div> <div class="modal-body"> <form name="categoryForm" ng-submit="submitForm()" novalidate> <!-- Id --> <div class="form-group" > <label>Id</label> <input type="text" name="Id" class="form-control" ng-model="category.Id" disabled> </div> <!-- NAME --> <div class="form-group" ng-class="{ 'has-error' : categoryForm.Name.$invalid && !categoryForm.Name.$pristine }"> <label>CatgeoryName</label> <input type="text" name="Name" class="form-control" ng-model="category.Name" required> <p ng-show="categoryForm.Name.$invalid && !categoryForm.Name.$pristine" class="help-block">You name is required.</p> </div> <!-- DESCRIPTION --> <div class="form-group" ng-class="{ 'has-error' : categoryForm.Description.$invalid && !categoryForm.Description.$pristine }"> <label>Description</label> <textarea name="Description" class="form-control" ng-model="category.Description" ng-minlength="3" ng-maxlength="800" required></textarea> <p ng-show="categoryForm.Description.$error.minlength" class="help-block">Description is too short.</p> </div> <button type="submit" class="btn btn-primary" ng-disabled="categoryForm.$invalid" > Submit changes </button> <button type="button" class="btn btn-default" data-dismiss="modal"> Close </button> </form> </div> @*<div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal"> Close </button> <button type="button" class="btn btn-primary"> Submit changes </button> </div>*@ </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal --> </div> <script> // create angular app var createCatgeoryApp = angular.module('createCatgeoryApp', []); // create angular controller and inject service createCatgeoryApp.controller('createCategoryController', function ($scope, categoryService) { //List all caetgory categoryService.getCategories().then(function (data) { $scope.categories = data.data; console.log($scope.categories); }, function () { alert('error'); }); // function to submit the form after all validation has occurred $scope.submitForm = function () { // check to make sure the form is completely valid if ($scope.categoryForm.$valid) { var category = $scope.category; console.log(category); categoryService.addCategory(category).then(function (data) { console.log(data); if (data.data.result == true) { //Update Scope to reflect dynamic changes $scope.categories.unshift(category); alert('Category Saved Successfully'); //Clear angular form $scope.categoryForm.$setPristine(); document.getElementById('myModal').modal('hide'); } }, function (error) { alert('Oops'); }); } }; $scope.editCategory = function(category) { $scope.category = category; }; $scope.deleteCategory = function(category) { console.log(category); categoryService.deleteCategory(category).then( function (data) { console.log(data); $scope.categories = $scope.categories.filter(function (item) { return item.Id !== category.Id; }); }, function() { alert('error'); } ); }; }); createCatgeoryApp.service("categoryService", function ($http) { this.getCategories = function () { var response = $http({ method: "GET", url: "/Settings/Category/CategoryList" }); return response; }; // Add Category this.addCategory = function (category) { // console.log(category); var response = $http({ method: "post", url: "/Settings/Category/CreateCategory", data: JSON.stringify(category), dataType: "json" }); return response; }; //Delete Employee this.deleteCategory = function (category) { var response = $http({ method: "POST", url: "/Settings/Category/DeleteCategory", data: JSON.stringify(category), dataType: "json", headers: { "Content-Type": "application/json" } //params: { // employeeId: JSON.stringify(employeeId) // } }); return response; }; }); </script> |