Hi,
change event is not working on edit functionality
while adding change funnctionality is working
Could please any body help me
@{
Layout = null;
}
var app = angular.module('MyApp', [])
app.directive("select2", function ($timeout, $parse) {
return {
restrict// Code goes here
: 'AC',
require: 'ngModel',
link: function (scope, element, attrs) {
console.log(attrs);
$timeout(function () {
element.select2();
element.select2Initialized = true;
});
var refreshSelect = function () {
if (!element.select2Initialized) return;
$timeout(function () {
element.trigger('change');
});
};
var recreateSelect = function () {
if (!element.select2Initialized) return;
$timeout(function () {
element.select2('destroy');
element.select2();
});
};
scope.$watch(attrs.ngModel, refreshSelect);
if (attrs.ngOptions) {
var list = attrs.ngOptions.match(/ in ([^ ]*)/)[1];
// watch for option list change
scope.$watch(list, recreateSelect);
}
if (attrs.ngDisabled) {
scope.$watch(attrs.ngDisabled, refreshSelect);
}
}
};
});
app.controller('MyController', function ($scope, $http, $window) {
$scope.EditCustomer;
$scope.EditIndex;
$scope.Customers = [];
GetCategory();
function GetCategory() {
$scope.categories = [];
$http({
method: 'Get',
url: '/autocomplete/GetCategories/',
}).success(function (data, status, headers, config) {
$scope.categories = data;
}).error(function (data, status, headers, config) {
$scope.message = 'Unexpected Error';
});
}
$scope.GetProducts = function () {
var countryId = $scope.Category.CategoryID;
var data = { "CategoryID": countryId };
var config = {
params: data,
headers: { 'Accept': 'application/json' }
};
if (countryId) {
$http.get("/autocomplete/GetProducts/'", config)
.then(function (data, status, headers, config) {
$scope.products = data.data;
}, function (response) {
alert(response.responseText);
});
}
else {
$scope.products = null;
}
}
$scope.Add = function () {
//Add the new item to the Array.
var customer = {};
customer.Category = $scope.Category.CategortName;
customer.Product = $scope.Product.ProductName;
$scope.Customers.push(customer);
//Clear the TextBoxes.
$scope.Category = "";
$scope.Product = "";
};
$scope.Remove = function (index) {
//Find the record using Index from Array.
var name = $scope.Customers[index].Name;
if ($window.confirm("Do you want to delete: " + name)) {
//Remove the item from Array using Index.
$scope.Customers.splice(index, 1);
}
}
$scope.edit = function (index) {
GetCategory();
//$scope.parentrow =true;
//Find the record using Index from Array.
$scope.EditCustomer = $scope.Customers[index];
$scope.Category = $scope.EditCustomer.Category;
$scope.CategoryIs = $scope.EditCustomer.Category;
$scope.Product = $scope.EditCustomer.Product;
$scope.ProductIs = $scope.EditCustomer.Product;
//$scope.Orders = $scope.EditCustomer.Orders;
//$scope.EditCustomer = $scope.Customers[index];
$scope.EditIndex = index;
alert($scope.EditCustomer);
}
$scope.Update = function (index) {
//$scope.parentrow = false;
alert("updated");
//Find the record using Index from Array.
$scope.EditCustomer.Category = $scope.CategoryIs;
$scope.EditCustomer.Product = $scope.ProductIs;
$scope.EditCustomer.Product = $scope.Product.ProductName;
$scope.Customers[index] = $scope.EditCustomer;
//$scope.Orders[index] = $scope.EditCustomer;
alert($scope.EditCustomer);
$scope.Category = "";
$scope.Product = "";
}
$scope.reset = function () {
$scope.Category = "";
$scope.Product = "";
}
});
| Category | Product | ||
|---|---|---|---|
| {{m.Category}} | {{m.Product}} | ||
Modal Header
| Category | Product | *@ | Action |
|---|---|---|---|
Controller
...............................
[HttpGet]
public ActionResult GetCategories()
{
db.Configuration.ProxyCreationEnabled = false;
var coun = db.Categories.Select(model => new { model.CategoryID, model.CategortName }).ToList();
return Json(coun, JsonRequestBehavior.AllowGet);
}
[HttpGet]
public ActionResult GetProducts(int? CategoryID)
{
db.Configuration.ProxyCreationEnabled = false;
var coun = db.Products.Where(model => model.ProductID == CategoryID).Select(model => new { model.ProductID, model.ProductName }).ToList();
return Json(coun, JsonRequestBehavior.AllowGet);
}
Suraj KumarPosted Dec 3, 2018, 7:34 AM