I tried to create a list page similar to the example in the sample like get Tasks, I did exactly similar way with different entity, not sure my dynamic web api service is not invoking from my js file. Here is the sample code. Not sure where I am going wrong. My Html file is loading with lists empty, do we need to have an y other settings apart from inheriting from IApplicationService? Please suggest me where I am missing, it is wasting time and making me feel wrong about this framework, this is an excellent framework which I liked the idea very well.
Js File
(function () { var app = angular.module('app');
var controllerId = 'sts.views.jobLocation.locationsList';
//var controllerId = 'locationsController';
app.controller(controllerId, [
'$scope', '$location', 'abp.services.tasksystem.jobLocation',
function ($scope, $location, jobLocationService) {
var vm = this;
//vm.localize = abp.localization.getSource('SimpleTaskSystem');
vm.jobLocationList = [];
$scope.selectedState = 0;
vm.filter1 = "test";
//$scope.$watch('selectedState', function (value) {
// vm.refreshJobLocations();
//});
// alert("I am here1");
vm.refreshJobLocations();
vm.refreshJobLocations = function () {
abp.ui.setBusy( //Set whole page busy until getTasks complete
null,
jobLocationService.getLocs({}).success(function (data) {
vm.jobLocationList = data.jobLocationsList;
})
);
};
vm.getLocationsCountText = function () {
return abp.utils.formatString(vm.localize('Xlocations'), vm.jobLocationList.length);
};
}
]);
})();
Cshtml <div class="panel panel-default" ng-controller="sts.views.jobLocation.locationsList as vm">
<br /><br />
<div class="panel-heading" style="position: relative;">
<br />
<div class="row">
<h3 class="panel-title col-xs-6">
TYest
</h3>
</div>
</div>
<ul class="list-group" ng-repeat="jobloc in vm.jobLocationList">
<div class="list-group-item">
<span>{{jobloc.JobLocationID}}</span>
<span> </span>
<span>{{jobloc.JobLocationName}}</span>
</div>
</ul>
</div>
-- Webapi service using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Abp.AutoMapper; using Abp.Application.Services; using Abp.Domain.Repositories; using SimpleTaskSystem.JobLocations.Dtos; using SimpleTaskSystem.JobLocations; using AutoMapper;
namespace SimpleTaskSystem.JobLocations { public class JobLocationAppService : ApplicationService,IJobLocationAppService {
private readonly IRepository<JobLocation> _jobLocationRepository;
public JobLocationAppService(IRepository<JobLocation> jobLocationRepository)
{
_jobLocationRepository = jobLocationRepository;
}
//public JobLocationAppService()
//{
// //_jobLocationRepository = new IJobLocationRepository();
//}
/*
private readonly IJobLocationRepository _jobLocationRepository;
public JobLocationAppService(IJobLocationRepository jobLocationRepository)
{
_jobLocationRepository = jobLocationRepository;
}
*/
public void CreateJobLocation(JobLocationDto jobLocationDTO)
{
Logger.Info("Creating a JobLocation for input: " + jobLocationDTO);
//if (null == jobLocationDTO)
// jobLocationDTO = new JobLocationDto();
JobLocation jobLocation = new JobLocation {
JobLocationID = jobLocationDTO.JobLocationID,
JobLocationName = jobLocationDTO.JobLocationName,
CreatedAt = DateTime.Now,
CreatedBy = "PrahladTest"
};
_jobLocationRepository.Insert(jobLocation);
}
public GetJobLocationsOutput GetLocs(GetJobLocationInput input)
{
Logger.Info("GetJobLocations for filter " );
List<JobLocationDto> jobLocationDtos = new List<JobLocationDto>();
List<JobLocation> jobLocationsList = _jobLocationRepository.GetAll().ToList();
jobLocationDtos = Mapper.Map<List<JobLocationDto>>(jobLocationsList);
return new GetJobLocationsOutput
{
JobLocationsList = Mapper.Map<List<JobLocationDto>>(jobLocationsList)
};
}
}
}
4 Answer(s)
-
0
Hi,
Can you try to call your app service from Chrome's developer console ? You can write something like this "abp.services.tasksystem.jobLocation.getLocs({})" and check if you can see any request on Chrome's network tab.
You can also check Logs.txt file under your web project. There might be some exception.
-
0
That is the problem, I am unable to see anything in the logs, my page loads with whatever static content it has. Event I kept alert it comes until that point but never invokes service.
-
0
As per your earlier suggestion when I load URL in Chrome I am getting error like this for this
vm.refreshJobLocations is not a function
angular.js:11655TypeError: vm.refreshJobLocations is not a function at new <anonymous> (<a class="postlink" href="http://localhost:6247/App/Main/views/jobLocation/list.js:25:16">http://localhost:6247/App/Main/views/jo ... t.js:25:16</a>) at Object.e [as invoke] (<a class="postlink" href="http://localhost:6247/Scripts/angular.min.js:36:315">http://localhost:6247/Scripts/angular.min.js:36:315</a>) at w.instance (<a class="postlink" href="http://localhost:6247/Scripts/angular.min.js:75:516">http://localhost:6247/Scripts/angular.min.js:75:516</a>) at <a class="postlink" href="http://localhost:6247/Scripts/angular.min.js:59:18">http://localhost:6247/Scripts/angular.min.js:59:18</a> at r (<a class="postlink" href="http://localhost:6247/Scripts/angular.min.js:7:408">http://localhost:6247/Scripts/angular.min.js:7:408</a>) at B (<a class="postlink" href="http://localhost:6247/Scripts/angular.min.js:59:2">http://localhost:6247/Scripts/angular.min.js:59:2</a>) at g (<a class="postlink" href="http://localhost:6247/Scripts/angular.min.js:51:335">http://localhost:6247/Scripts/angular.min.js:51:335</a>) at <a class="postlink" href="http://localhost:6247/Scripts/angular.min.js:50:444">http://localhost:6247/Scripts/angular.min.js:50:444</a> at <a class="postlink" href="http://localhost:6247/Scripts/angular-ui-router.min.js:7:22912">http://localhost:6247/Scripts/angular-u ... js:7:22912</a> at $ (<a class="postlink" href="http://localhost:6247/Scripts/angular.min.js:70:197">http://localhost:6247/Scripts/angular.min.js:70:197</a>)
-
0
Fixed by changing line vm.refreshJobLocations();
After function declaration.