Can anyone correct what Im doing here
Uncaught TypeError: Object function DataService($scope) {
this.$scope = $scope;
// Members Area
var addVessel = function (userId) {
alert("user"+userId);
};
} has no method 'addVessel'
Many Thanks – Im new to this
After reviewing the responses it seems the problem is nested higher up
This is the namespace/class
// Member Service Namespace
var MemberService;
(function (MemberService) {
// Member service type
var DataService = (function ($scope) {
// Construct the data service
function DataService($scope) {
this.$scope = $scope;
// Members Area
this.addVessel = function (userId) {
alert("user"+userId);
};
}
return DataService;
})();
MemberService.DataService = DataService;
})(MemberService || (MemberService = {}));
and this is the call
MemberService.DataService.addVessel('XXX');
You never add the method
addVessel()to the object, but use it just as a “private” method within the object’s scope.Use this instead:
EDIT
Your error seems to be, that you create a constructor function with
DataService, but never actually call this constructor.So one solution would be to change this line
into
This will create a new instance of your
`DataServiceand attach this toMemberService.DataService.If you, however, want to create multiple instances, your code would be right so far, but in order to call, you first have to create an object of this constructor: