You need to sign in to do that
Don't have an account?
GauravG
Print Data from JSON using AngularJS in Visualforce Page
Hello I am using below code to generate JSON and consuming the JSON data to reterive values and render on Visualforce page but it is showing nothing.
VisualForce to Print JSON
-----------------------------
<apex:page contentType="text/html" standardStylesheets="false" controller="P_GenerateJSONString" sidebar="false" showHeader="false" >
<apex:outputText value="{!lstAccountsJSONString}" ></apex:outputText>
</apex:page>
Controller to Generate JSON
-----------------------------
public with sharing class P_GenerateJSONString {
List<Account> lstAccounts {get;set;}
public String lstAccountsJSONString {get;set;}
public P_GenerateJSONString() {
lstAccounts = [SELECT id, name FROM Account LIMIT 1];
printJSON();
}
public String printJSON() {
lstAccountsJSONString = JSON.serializePretty(lstAccounts);
return lstAccountsJSONString;
}
}
VisualForce Page Consume JSON Data
----------------------------------------
<apex:page >
<script>
<apex:includeScript value="{!$Resource.AngularJS}"/>
var app = angular.module('myApp',[]);
app.controller("customersController", function($scope,$http) {
$http.get("http://www.w3schools.com/website/Customers_JSON.php").success(function(response) {$scope.names = response;});
});
</script>
<body ng-app="myApp" >
<div ng-controller="customersController">
<ul>
<li ng-repeat="acct in names">
{{acct.City}}
</li>
</ul>
</div>
</body>
</apex:page>
Please suggest what is wrong.
Thanks
VisualForce to Print JSON
-----------------------------
<apex:page contentType="text/html" standardStylesheets="false" controller="P_GenerateJSONString" sidebar="false" showHeader="false" >
<apex:outputText value="{!lstAccountsJSONString}" ></apex:outputText>
</apex:page>
Controller to Generate JSON
-----------------------------
public with sharing class P_GenerateJSONString {
List<Account> lstAccounts {get;set;}
public String lstAccountsJSONString {get;set;}
public P_GenerateJSONString() {
lstAccounts = [SELECT id, name FROM Account LIMIT 1];
printJSON();
}
public String printJSON() {
lstAccountsJSONString = JSON.serializePretty(lstAccounts);
return lstAccountsJSONString;
}
}
VisualForce Page Consume JSON Data
----------------------------------------
<apex:page >
<script>
<apex:includeScript value="{!$Resource.AngularJS}"/>
var app = angular.module('myApp',[]);
app.controller("customersController", function($scope,$http) {
$http.get("http://www.w3schools.com/website/Customers_JSON.php").success(function(response) {$scope.names = response;});
});
</script>
<body ng-app="myApp" >
<div ng-controller="customersController">
<ul>
<li ng-repeat="acct in names">
{{acct.City}}
</li>
</ul>
</div>
</body>
</apex:page>
Please suggest what is wrong.
Thanks