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

VisualForce Remoting not working with Separate AngularJS Controller File
I'm facing an issue while working with Visualforce remoting and angularjs. Whenever I'm putting my controller code in separate js Static resource, my code doesn't work. Please help me in figuring out this. ( Below code works if i include controller script in same VF page)
My Visualforce page
My Controller Static Resource
My Apex Controller
My Visualforce page
<apex:page controller="ApexRemoteActionPageController" docType="html-5.0"> <html> <body> <div class="bootstrap" ng-app="ngApp" ng-controller="ContactCtrl" > <h1 align="center">Click The Button</h1> <button ng-click="getContacts()" class="btn btn-lg btn-default btn-block">Get Contacts</button> <p> <ul> <li id="{{current.Id}}" ng-repeat="current in contacts" ng-class-even="'rowEven'">{{current.Name}}</li> </ul> </p> </div> <apex:stylesheet value="//cdn.jsdelivr.net/webjars/bootstrap-sf1/0.1.0-beta.6/css/bootstrap-namespaced.css"/> <apex:includeScript value="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.11/angular.min.js"/> <apex:includeScript value="{!$Resource.ContactCtrl}" /> </body> </html> </apex:page>
My Controller Static Resource
<script> var ngApp= angular.module("ngApp", []); ngApp.controller("ContactCtrl", ["$scope", function($scope) { $scope.contacts = []; $scope.getContacts = function() { ApexRemoteActionPageController.myContacts(function(result, event) { $scope.contacts = result; $scope.$apply(); }); } }]); </script>
My Apex Controller
global class ApexRemoteActionPageController { @RemoteAction global static List<Contact> myContacts() { return [select id, name, email from Contact Order By LastModifiedDate DESC LIMIT 30]; }
Syntax is different when referring to the static resource
it should be
namespace.ControllerName.ControllerMethod.
for default namspace go the packages from the setup
let me know if you have any issues.
Thanks,
pRAMODH.
All Answers
Syntax is different when referring to the static resource
it should be
namespace.ControllerName.ControllerMethod.
for default namspace go the packages from the setup
let me know if you have any issues.
Thanks,
pRAMODH.