Reputation: 43
browserLink:37 Uncaught Error: Syntax error, unrecognized expression: input#{role}(…)
//template
<div ng-repeat="role in roles">
<input type="checkbox" id="{{role}}" value="{{role}}" ng-model="role" ng -checked="getCheckedTrue[{{role}}]" />
{{role}}
</div>
//js
$scope.roles = [
'Dentist',
'HeartSurgeon',
'Cance'
];
$scope.getCheckedTrue = function (data) {
console.log(data);
$http({
method: 'GET',
url: '/Doctor/getType?searchString=' + $scope.role,
}).then(function successCallback(responce) {
$scope.Doctors = responce.data;
}, function errorCallback(response) {
alert("Error : " + response.data.ExceptionMessage);
});
};`
//Controller
public JsonResult getType(string searchString)
{
var Doctor = db.DocMaster.Where(f =>
f.DocType.StartsWith(searchString)).ToList();
var JsonResult = Json(Doctor, JsonRequestBehavior.AllowGet);
JsonResult.MaxJsonLength = int.MaxValue;
return JsonResult;
}
Upvotes: 1
Views: 129
Reputation: 43
//For getting the all records from database. Controller
//c# controller
public JsonResult get(string searchString)
{
var Doctor = db.DocMaster.Where(f =>
f.DocType.StartsWith(searchString)).ToList();
var JsonResult = Json(Doctor, JsonRequestBehavior.AllowGet);
JsonResult.MaxJsonLength = int.MaxValue;
return JsonResult;
}
//View
<div ng-repeat="(typeKey, typeVal) in roles">
<div ng-repeat="value in typeVal">
<label>
<input type="checkbox"
ng-model="x"
ng-change="setOutput(typeKey, $index, value)">{{value}}
</label>
</div>
</div>
//angular-controller
$scope.outputs = {};
$scope.setOutput = function (typeKey, $index, value) {
$scope.Doctors = {};
$http({
method: 'POST',
url: '/Doctor/get?searchString='+value,
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
console.log(response);
$scope.Doctors = response.data;
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
alert("Error : " + response.data.ExceptionMessage);
});
};
Upvotes: 1
Reputation: 493
getCheckedTrue is function and you are using it as an array.
so, instead of getCheckedTrue[{{role}}] it should be getCheckedTrue({{role}})
Also, the role value is string so you better to use getCheckedTrue('{{role}}')
Upvotes: 0
Reputation: 749
I believe ng-checked="getCheckedTrue[{{role}}]" should in fact be ng-checked="getCheckedTrue[role]"
Upvotes: 0