Reputation: 1
I get the following error - angular.js:38Uncaught Error: [$injector:unpr] http://errors.angularjs.org/1.5.5/$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope
I am trying to send a subscribe message, using pubnub, and incorporate an ng-notifications-bar for whether the subscribe message comes through successfully or not.
The code is as follows for the controller, the main parts which I am not sure about is the ngNotifications part, (showError, showSuccess, showWarning etc). You will see in the last part I've implemented an if else statement to specify when to apply a success notification and when to apply an error notification:
myApp.controller('NotificationsController',['$scope','$http','$rootScope','$location','token_service','PubNub','notifications', function($scope,$http,$rootScope,$location,token_service,PubNub,notifications){
$scope.noti = [];
function theCallback (x){
$scope.$apply(function () {
$rootScope.spinner = false;
$scope.noti = x[0];
console.log(x[0]);
});
}
$scope.showError = function () {
notifications.showError("Error, are you sure you've followed the correct process?");
};
$scope.showWarning = function () {
notifications.showWarning('Having trouble, please try again.');
};
$scope.showSuccess = function () {
notifications.showSuccess('Welcome to Chui!');
};
$rootScope.defaultInstance.history({channel:"chui_channel", count:100,callback:theCallback});
$rootScope.spinner = true;
$scope.keys='test_notifications'
}])
//myApp.controller('SignoutController',['$scope','$rootScope','$location','token_service','signout_service','$window',function($scope,$rootScope,$location,token_service,signout_service,$window){
myApp.run(function($scope,$rootScope,$location,$templateCache,$window,$cookies,$route,api_service,notifications) {
$rootScope.defaultInstance = PUBNUB.init({
publish_key: 'pub-c-5aace072-1c95-4d6c-8b95-28638c4bd6a2',
subscribe_key: 'sub-c-0ac5d634-10aa-11e6-bbd9-02ee2ddab7fe'
});
var device = api_service.get_devices()
device.then(function(response){
$rootScope.devices = response;
console.log(response);
var deviceSerialList = new String
for (var d in response){
deviceSerialList = String(response[d].DeviceId) +',';
var l = deviceSerialList.split(',').filter(Boolean);
if (l.length == response.length){
listen(deviceSerialList);
console.log(deviceSerialList);
$scope.showSuccess = function () {
notifications.showSuccess('Welcome to Chui!');
};
}
else{
$scope.showError = function () {
notifications.showError("Error, are you sure you've followed the correct process?");
};
}
};
});
function listen(deviceList){
$rootScope.defaultInstance.subscribe({
channel : deviceList,
message : function (message, envelope, channelOrGroup, time, channel) {
alert(message)
console.log(
"Message Received." + "\n" +
"Channel or Group : " + JSON.stringify(channelOrGroup) + "\n" +
"Channel : " + JSON.stringify(channel) + "\n" +
"Message : " + JSON.stringify(message) + "\n" +
"Time : " + time + "\n" +
"Raw Envelope : " + JSON.stringify(envelope)
)
},
});
};
In the html page I have included the following: and it already has
Upvotes: 0
Views: 142
Reputation: 104795
myApp.run(function($scope
- this is the cause. .run
doesn't take a $scope
injection - remove it.
Upvotes: 0