You need to sign in to do that
Don't have an account?

AngularJs not rendering when used with Visualforce Remoting
I'm having trouble rendering angularjs with the below code
APex COntroller Code:
VisualForce Page as well as AngularJs
I have tried several options like using Visualforce merge fields for remoting, removal of html tags.. and all but the above code is not detecting angularjs and nothing execution of code happens.
Please suggest.
APex COntroller Code:
global class ApexRemoteInvokeManagerController { public ApexRemoteInvokeManagerController() { } public ApexRemoteInvokeManagerController(ApexPages.StandardController controller) { } @RemoteAction global static void saveAccountWithContact(String contactJson,String accountJson) { Account a = (Account)JSON.deserialize(accountJson,Account.class); insert a; Contact c = (Contact)JSON.deserialize(contactJson, Contact.class); c.AccountId = a.Id; upsert c; } }
VisualForce Page as well as AngularJs
<apex:page controller="ApexRemoteInvokeManagerController" docType="html-5.0" sidebar="false"> <html> <head> <link href="//cdn.jsdelivr.net/webjars/bootstrap-sf1/0.1.0- beta.6/css/bootstrap-namespaced.css" rel="stylesheet"/> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0- beta.11/angular.min.js"></script> <script> var accountApp = angular.module('accountApp',[]); accountApp.factory('accountAndContactsFactory', ['$q', '$rootScope', function($q, $rootScope) { this.save = function() { var deferred = $q.defer(); var contactJson = JSON.stringify(contact); var accountJson = JSON.stringify(account); Visualforce.remoting.Manager.invokeAction( 'ApexRemoteInvokeManagerController.saveAccountWithContact', contactJson, accountJson, function(result, event) { $rootScope.$apply(function() { if (event.status) { deferred.resolve(result); } else { deferred.reject(event); } }) }, { buffer: true, escape: true, timeout: 30000 } ); return deferred.promise; } }]); accountApp.controller('MainController',function($scope, 'accountAndContactsFactory',function($scope, accountAndContactsFactory)) { $scope.save = function(contact,account){ accountAndContactsFactory.save(contact,account).then(function(result) {$scope.message = "success";}, function(error) {$scope.message = "wrong";} ) } }); </script> </head> <body> <div class="bootstrap" ng-app="accountApp" ng- controller="MainController"> <form name="simpleForm" novalidate="novalidate"> <table> <tr> <td>First Name:</td><td><input type="text" name="FirstName" ng- model="contact.FirstName"/></td> </tr> <tr> <td>Last Name:</td><td><input type="text" required="true" name="LastName" ng-model="contact.LastName"/> <span class="error" ng- show="simpleForm.LastName.$error.required">Required!</span></td> </tr> <tr> <td>Business Name:</td><td><input type="text" required="true" name="BusinessName" ng-model="account.Name"/> <span class="error" ng- show="simpleForm.BusinessName.$error.required">Required!</span></td> </tr> <tr> {{message}} </tr> <tr> <input type="button" ng-click="save(contact,account)" ng- disabled="simpleForm.$pristine || simpleForm.$dirty && simpleForm.$invalid" value="Save"/> </tr> </table> </form> </div> </body> </html> </apex:page>
I have tried several options like using Visualforce merge fields for remoting, removal of html tags.. and all but the above code is not detecting angularjs and nothing execution of code happens.
Please suggest.
Angular Controller
Need to move getcontacts to Factory as well...but ...here's the code for someone ...who is stuck like me.