Angular js injection error when app is loaded on browser - javascript

I get this error: [$injector:modulerr] http://errors.angularjs.org/1.3.0/$injector/modulerr?p0=myTmoApp.pdl&p1=Err…rkspace%2Fnetbeans-workspace%2FJsonParsing%2Fweb%2Fangular.min.js%3A18%3A3)
I have properly injected all services and scopes but still I get this error when I run the app.
Here is the code:
var app = angular.module("myTmoApppdl", []);
app.controller("myCtrl", function ($scope, jsonParsingService) {
var digitalData = digitalData || {};
digitalData =
{
"page": {
"pageInfo": {
"pageID": "12345",
"pageName": "smartphones:samsung-galaxy-s-5",
"pageURL": "www.t-mobile.com/products/smartphonesSamsungGalaxyS5",
"previousPageURL": "www.t-mobile.com/products/smartphones",
"prevPageName": "phones",
"version": "1.15",
"language": "en-US",
"geoRegion": "US",
"domain": "t-mobile.com",
"responsiveState": "desktop",
"timeStamp": "2015-03-23T20:52:23.563Z",
"currencyCode": "USD"
},
"category": {
"primaryCategory": "shop",
"subCategory": ["smartphones"],
"pageType": "product details",
"variant": "",
"channel": "",
"subChannel": "",
"flowName": "",
"storeID": "",
"referringApp": "tapestry"
},
"search": {
"searchTerm": "",
"searchResultCount": 0
}
}
};
digitalData = JSON.stringify(digitalData);
console.log("json to be parsed is: " + digitalData);
$scope.myTxt = "You have not parsed json yet";
$scope.myFunc = function () {
jsonParsingService.parseMyJson(digitalData);
$scope.myTxt = "Json parsing complete!";
console.log("Json parsing complete");
};
});
Service:
app.service('jsonParsingService', function () {
this.parseMyJson = function (json) {
var obj = JSON.parse(json);
console.log(obj);
};
});
It is just a sample app I am trying to run but unable to figure out what went wrong
Script files:
<script src="https://code.angularjs.org/1.3.0-rc.2/angular.min.js"></script>
<script src="parseJson.js" type="text/javascript"></script>

You have to pass in the service in the following format to the Controller. See the array notation.
.controller('myCtrl', ['$scope', 'jsonParsingService',function($scope,jsonParsingService){
//controller code here
}]);
See the docs about Dependency Injection here

It seems that your angular.js wasn't available. Please see a running example in this bin

Related

Razor pay route payments using php

ive been using razor pays normal checkout feature
<script type="text/javascript">
var options = {
"key": "rzp_****_*********",
"amount": 10000,
"currency": "INR",
"name": "XYZ",
"description": "Payment For Appointment at XYZ Limited",
"image": "https://XYZ.in/public/theme/images/re-logo.png",
"handler": function (response) {
var payid = response.razorpay_payment_id;
$('#transaction_id').val(payid);
$('#paymentform').submit();
},
"prefill": {
"name": "Name",
"email": "Email"
},
"notes": {
"address": "note value"
},
"theme": {
"color": "#F37254"
}
};
var rzp1 = new Razorpay(options);
document.getElementById('payonlinebutton').onclick = function (e) {
rzp1.open();
e.preventDefault();
}
</script>
But i want to use route payments now, and on razorpay's document they have only sample code for curl
Can anyone help me with php solution if there is any.
i got his document but the concept is not that clear
https://razorpay.com/docs/server-integration/php/usage/#route
Install PHP SDK https://razorpay.com/docs/server-integration/php/ and call the function as per need

AngularJS $http.get not pulling back

Why is this not pulling back anything? I keep getting the error message and I cannot figure out why. I tried to use JSONParse on the response data and reassigning it to the $scope but that didn't help. I have no errors in my F12 Console. I know JQuery is a much better solution but I prefer the Javascript, i'll take both though. Thanks ahead of time.
var controlSeletor = angular.module('moduleName', []);
controlSeletor .controller('variableController', function($scope, $http) {
$http.get("data.json")
.then(
function(response) {
// Success
$scope.variable = response.data;
},
function(response){
// Error
alert("Error!");
}
);
});
The json is a separate file and looks like this:
[{
"url": "place.html",
"name": "Bob",
"pic": "bob.jpg"
},
{
"url": "place.html",
"name": "Mike",
"pic": "mike.jpg"
},
{
"url": "place.html",
"name": "Tony",
"pic": "tony.jpg"
}];
Your JSON is not valid, change it as follows,
[ {
"url": "place.html",
"name": "Bob",
"pic": "bob.jpg" }, {
"url": "place.html",
"name": "Mike",
"pic": "mike.jpg" }, {
"url": "place.html",
"name": "Tony",
"pic": "tony.jpg" } ]
var app = angular.module('filterApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.get('data.json').
then(function(response) {
$scope.variable = response.data;
});
});
DEMO
Few observations :
Controller declaration is not correct. It should be controlSeletor.controller instead of controlSeletor .controller.
Your JSON is not a valid JSON.
Valid JSON should be like this :

Refreshing Angular App takes to the default state

I am creating angularjs based Dashboeard, I am using ui.router to create states from json file,
My topNavbar and states are being created by pages.json file.
My app works fine but when refresh the page with this"localhost:#/map" url it redirects to "localhost:#/dashboard" state.
how I can set the state which user enters in URL?
var $urlRouterProviderRef = null;
var $stateProviderRef = null;
myApp.run(function ($q, $rootScope, $state, $http, navbars)
{
navbars.load()
$http.get("js/config/pages.json")
.success(function (data) {
angular.forEach(data, function (value, key) {
var state = {
"url": value.url,
"templateUrl": value.templateUrl,
"controller": value.controller
};
$stateProviderRef.state(value.sref, state);
});
});
}
myApp.config(function ($stateProvider, $locationProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/dashboard');
$urlRouterProviderRef = $urlRouterProvider;
$stateProviderRef = $stateProvider;
})
pages.json
[
{
"displayname": "Dashboard",
"active": true,
"name": "dashboard",
"sref": "dashboard",
"url": "/dashboard",
"controller": "layoutOneCtrl",
"templateUrl": "views/dashboard.html",
"icon": "fa-dashboard",
"children": [{
"name": "dashboard"
}]
}, {
"displayname": "Map",
"open": false,
"active": false,
"name": "map",
"sref": "map",
"url": "/map",
"templateUrl": "views/layout1.html",
"controller": "layoutOneCtrl",
"icon": "fa-map-marker",
"children": [{
"name": "map"
}]
}
.
.
.
]
when you refresh page , your run function called and read value from pages.json , you need to update pages.json file or you need to save the url value in localstorage or sessionstorage so whenever you refresh the page you can access url value from localstorage or sessionstorage.

Construct models from a Collection fetch in Backbone.js

I am using Backbone to retrieve data over a REST API. My code is as follows:
var PlayerModel = Backbone.Model.extend({});
var PlayersCollection = Backbone.Collection.extend({
url: "http://api.football-data.org/v1/teams/81/players",
model: PlayerModel
});
var catalons = new PlayersCollection();
catalons.fetch();
This is the JSON output I receive if I do a GET request in POSTMAN
{
"_links": {
"self": {
"href": "http://api.football-data.org/v1/teams/81/players"
},
"team": {
"href": "http://api.football-data.org/v1/teams/81"
}
},
"count": 24,
"players": [
{
"name": "Marc-André ter Stegen",
"position": "Keeper",
"jerseyNumber": 1,
"dateOfBirth": "1992-04-30",
"nationality": "Germany",
"contractUntil": "2019-06-30",
"marketValue": "15,000,000 €"
},
{
"name": "Claudio Bravo",
"position": "Keeper",
"jerseyNumber": 13,
"dateOfBirth": "1983-04-13",
"nationality": "Chile",
"contractUntil": "2018-06-30",
"marketValue": "15,000,000 €"
}
]
}
I am successfully able to receive data using fetch, the thing which I am unable to figure out is how do I parse the fetched data so that my collection catalons will contain nothing but only the players? i.e. similar to if I had set it up this way:
var catalons = new PlayersCollection(playerModelArray);
You can do this using Backbone's Collection parse method. You simply need to add a parse method to your PlayersCollection prototype definition:
var PlayersCollection = Backbone.Collection.extend({
url: "http://api.football-data.org/v1/teams/81/players",
model: PlayerModel,
parse: function (response) {
return response.players;
}
});

Having trouble using data retrieved with json in javascript, cannot sort the array

I am trying to sort out the data I retrieved from an api with javascript.
Code :
function getResults() {
var url = $.getJSON("http://api.api.com&leagues=SOCENGPRE&lang=en&format=jsonp&callback=?", function(jsondata){;
for(var i = 0; i < jsondata.length; i++)
for(var id in jsondata[i]) {
console.log("ID - " + id);
console.log("TEAM - " + jsondata[i][id].home_team);
}
});
}
Example of data retrieved :
{
"SOCENGPRE": {
"league_name": "Barclays Premier League",
"league_phid": null,
"league_type": null,
"fixtures": [
{
"id": "64714",
"code": "SOCENGPRE",
"event_slug": "west_ham-tottenham-1401290",
"home_team": "West Ham",
"away_team": "Tottenham",
},
{
"id": "64711",
"code": "SOCENGPRE",
"event_slug": "manchester_u-sunderland-1401286",
"home_team": "Manchester U",
"away_team": "Sunderland"
}
But using my code I cannot seem to get the results I am wanting.
I want to print out every games ID and Home Team. Any insights on why is my code not working? Thank you very much in advance!
UPDATE: I have removed the extra semi-colon but it's still not printing the data for me.
UPDATE 2: Regarding the requests for the URL. When I call it in a browser I get this huge result
?({"SOCENGPRE":{"league_name":"Barclays Premier League","league_phid":null,"league_type":null,"fixtures":[{"id":"64714","code":"SOCENGPRE","event_slug":"west_ham-tottenham-1401290","start":"1399117500","home_team":"West Ham","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t523.png","home_team_short":"","away_team":"Tottenham","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t498.png","away_team_short":"","phid":null},{"id":"64711","code":"SOCENGPRE","event_slug":"manchester_u-sunderland-1401286","start":"1399125600","home_team":"Manchester U","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t20790.png","home_team_short":"Man U","away_team":"Sunderland","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t382.png","away_team_short":"","phid":null},{"id":"64712","code":"SOCENGPRE","event_slug":"stoke-fulham-1401288","start":"1399125600","home_team":"Stoke","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t389.png","home_team_short":"","away_team":"Fulham","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t379.png","away_team_short":"","phid":null},{"id":"64706","code":"SOCENGPRE","event_slug":"aston_villa-hull-1401282","start":"1399125600","home_team":"Aston Villa","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t380.png","home_team_short":"","away_team":"Hull","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t511.png","away_team_short":"Hull","phid":null},{"id":"64710","code":"SOCENGPRE","event_slug":"newcastle-cardiff-1401287","start":"1399125600","home_team":"Newcastle","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t385.png","home_team_short":"","away_team":"Cardiff","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t524.png","away_team_short":"","phid":null},{"id":"64713","code":"SOCENGPRE","event_slug":"swansea-southampton-1401289","start":"1399125600","home_team":"Swansea","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t384.png","home_team_short":"Swansea","away_team":"Southampton","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t8482.png","away_team_short":"","phid":null},{"id":"64709","code":"SOCENGPRE","event_slug":"everton-manchester_c-1401285","start":"1399134600","home_team":"Everton","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t499.png","home_team_short":"","away_team":"Manchester C","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t383.png","away_team_short":"Man C","phid":null},{"id":"64707","code":"SOCENGPRE","event_slug":"arsenal-west_bromwich-1401281","start":"1399206600","home_team":"Arsenal","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t30773.png","home_team_short":"","away_team":"West Bromwich","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t816.png","away_team_short":"West Brom","phid":null},{"id":"64705","code":"SOCENGPRE","event_slug":"chelsea-norwich-1401283","start":"1399215600","home_team":"Chelsea","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t497.png","home_team_short":"","away_team":"Norwich","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t1438.png","away_team_short":"","phid":null},{"id":"64708","code":"SOCENGPRE","event_slug":"crystal_palace-liverpool-1401284","start":"1399316400","home_team":"Crystal Palace","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t518.png","home_team_short":"C. Palace","away_team":"Liverpool","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t381.png","away_team_short":"","phid":null},{"id":"64679","code":"SOCENGPRE","event_slug":"manchester_u-hull-1401252","start":"1399401900","home_team":"Manchester U","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t20790.png","home_team_short":"Man U","away_team":"Hull","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t511.png","away_team_short":"Hull","phid":null},{"id":"64630","code":"SOCENGPRE","event_slug":"manchester_c-aston_villa-1401198","start":"1399488300","home_team":"Manchester C","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t383.png","home_team_short":"Man C","away_team":"Aston Villa","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t380.png","away_team_short":"","phid":null},{"id":"64621","code":"SOCENGPRE","event_slug":"sunderland-west_bromwich-1401189","start":"1399488300","home_team":"Sunderland","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t382.png","home_team_short":"","away_team":"West Bromwich","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t816.png","away_team_short":"West Brom","phid":null},{"id":"64719","code":"SOCENGPRE","event_slug":"manchester_c-west_ham-1401296","start":"1399816800","home_team":"Manchester C","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t383.png","home_team_short":"Man C","away_team":"West Ham","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t523.png","away_team_short":"","phid":null},{"id":"64717","code":"SOCENGPRE","event_slug":"liverpool-newcastle-1401295","start":"1399816800","home_team":"Liverpool","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t381.png","home_team_short":"","away_team":"Newcastle","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t385.png","away_team_short":"","phid":null},{"id":"64720","code":"SOCENGPRE","event_slug":"norwich-arsenal-1401297","start":"1399816800","home_team":"Norwich","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t1438.png","home_team_short":"","away_team":"Arsenal","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t30773.png","away_team_short":"","phid":null},{"id":"64715","code":"SOCENGPRE","event_slug":"fulham-crystal_palace-1401293","start":"1399816800","home_team":"Fulham","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t379.png","home_team_short":"","away_team":"Crystal Palace","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t518.png","away_team_short":"C. Palace","phid":null},{"id":"64722","code":"SOCENGPRE","event_slug":"sunderland-swansea-1401299","start":"1399816800","home_team":"Sunderland","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t382.png","home_team_short":"","away_team":"Swansea","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t384.png","away_team_short":"Swansea","phid":null},{"id":"64723","code":"SOCENGPRE","event_slug":"tottenham-aston_villa-1401300","start":"1399816800","home_team":"Tottenham","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t498.png","home_team_short":"","away_team":"Aston Villa","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t380.png","away_team_short":"","phid":null},{"id":"64724","code":"SOCENGPRE","event_slug":"west_bromwich-stoke-1401301","start":"1399816800","home_team":"West Bromwich","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t816.png","home_team_short":"West Brom","away_team":"Stoke","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t389.png","away_team_short":"","phid":null},{"id":"64718","code":"SOCENGPRE","event_slug":"hull-everton-1401294","start":"1399816800","home_team":"Hull","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t511.png","home_team_short":"Hull","away_team":"Everton","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t499.png","away_team_short":"","phid":null},{"id":"64721","code":"SOCENGPRE","event_slug":"southampton-manchester_u-1401298","start":"1399816800","home_team":"Southampton","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t8482.png","home_team_short":"","away_team":"Manchester U","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t20790.png","away_team_short":"Man U","phid":null},{"id":"64716","code":"SOCENGPRE","event_slug":"cardiff-chelsea-1401292","start":"1399816800","home_team":"Cardiff","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t524.png","home_team_short":"","away_team":"Chelsea","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t497.png","away_team_short":"","phid":null}]}});
Link to pastebin for easier reading of the data
Change your getResults function to be called after the JSON has been parsed, like so:
var myDataVar;
$.ajax({
url: "URL to JSON file here",
dataType: "text", //If you get an error here, change the type to "text"
success: function (data) {
myDataVar = $.parseJSON(data);
getResults();
}
});
The above code will save the JSON file's parsed data into a single variable.
It will then call a function to get the results, being this function:
function getResults() {
var fixturesLength = myDataVar.SOCENGPRE.fixtures.length - 1;
for (var i = 0; i <= fixturesLength; i++) {
console.log(myDataVar.SOCENGPRE.fixtures[i].id);
}
}
The above loop will print to the console every one of your fixtures ID's.
Test data used:
{
"SOCENGPRE": {
"league_name": "Barclays Premier League",
"league_phid": null,
"league_type": null,
"fixtures": [{
"id": "64714",
"code": "SOCENGPRE",
"event_slug": "west_ham-tottenham-1401290",
"start": "1399117500",
"home_team": "West Ham",
"home_team_phid": null,
"home_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t523.png",
"home_team_short": "",
"away_team": "Tottenham",
"away_team_phid": null,
"away_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t498.png",
"away_team_short": "",
"phid": null
}, {
"id": "64711",
"code": "SOCENGPRE",
"event_slug": "manchester_u-sunderland-1401286",
"start": "1399125600",
"home_team": "Manchester U",
"home_team_phid": null,
"home_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t20790.png",
"home_team_short": "Man U",
"away_team": "Sunderland",
"away_team_phid": null,
"away_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t382.png",
"away_team_short": "",
"phid": null
}, {
"id": "64712",
"code": "SOCENGPRE",
"event_slug": "stoke-fulham-1401288",
"start": "1399125600",
"home_team": "Stoke",
"home_team_phid": null,
"home_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t389.png",
"home_team_short": "",
"away_team": "Fulham",
"away_team_phid": null,
"away_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t379.png",
"away_team_short": "",
"phid": null
}]
}
}
Console results:
64714
64711
64712

Categories