Can you please assist in finding why $Scope.notify is undefined, infact the other function is working totally fine.
services.js [ postmain and allresults are working fine but not notifyadd??]
services.factory('PFactory', ['$resource', function ($resource) {
alert("I am here service");
return {
postmain: $resource('/ngdemo/web/posts', {}, {
query: {method: 'GET', isArray: true },
create: {method: 'POST'}
}),
allresults: $resource('/ngdemo/web/posts/result/:tag', {}, {
query: {method: 'GET', params: {tag: '@tag'} },
create: {method: 'POST'}
}),
notifyadd: $resource('/ngdemo/web/notify', {}, {
query: {method: 'GET', isArray: true },
create: {method: 'POST'}
}),
allnotifications: $resource('/ngdemo/web/posts/result/:key', {}, {
query: {method: 'GET', params: {tag: '@key'} },
create: {method: 'POST'}
})};
}]);
CONTROLLER.js
app.controller('MyCtrl2', ['$scope', 'PFactory', '$location', function ($scope, PFactory, $location) {
$scope.createPost = function () {
PFactory.postmain.create($scope.UserPost)
$scope.allposts.push($scope.UserPost);
$scope.UserPost = "";
}
$scope.notify = function () {
console.log("in notify" + $scope.Notify.secEmail);
PFactory.notifyadd.create($scope.Notify)
}
}]);
HTML file:
<form role="form">
<div class="row">
<div class="col-xs-8 col-md-4">
<div class="form-group">
<input type="text" ng-model='Notify.secEmail'
placeholder="Email of the person who can help?" class="form-control"
></div>
</div>
<div class="col-xs-8 col-md-4">
<div class="form-group">
<input type="text" ng-model="Notify.message"
placeholder="Enter a Message or Phone number" class="form-control"
>
<!-- <input type="hidden" ng-model="Notify.loggedInEmail" ng-value="{{ result.first_name }}" />
<input type="hidden" ng-model="Notify.postId" ng-value="{{ post.id }}" />
<input type="hidden" ng-model="Notify.destEmail" ng-value="{{ post.userEmail }}" />-->
</div>
</div>
<div class="col-xs-6 col-md-3">
<button class="btn btn-danger" ng-click="notify()" type="button">
Notify
</button>
<!--<input type="submit" ng-click='notify()' value="Notify"
class="btn btn-danger btn-block btn-sm" tabindex="7">-->
</div>
</div>
</form>
ERROR I am getting is:
Error: $scope.Notify is undefined $scope.notify@http://pingle.com:8080/ngdemo/js/controllers.js:213
Same works with postmain create function but not with Notify!! Any idea?
notify()
but not the objectNotify
- where has it been defined? As the error states, the object is undefined - which is correct. I can't see any definition of it, yet you use its properties in your view (and also seem to submit an HTTP POST request using that object) – callmekatootie Apr 1 at 10:05