0

AngularJS is showing following error in browser console,

Error: [$injector:nomod] Module 'SharePointAngApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. http://errors.angularjs.org/1.4.0-beta.6/$injector/nomod?p0=SharePointAngApp.

I have defined SharePointAngApp already and the JS which consists the code is already been reffered in head section below the reference of angularJS. But still it is throwing an error, don't know why it is not getting that app. Any help would be appreciated though I am new to angularJS.

jQuery(document).ready(
function () {

   SP.SOD.executeOrDelayUntilScriptLoaded(hideQuicklinks, 'sp.js');   

});




var currentUser;
var clientContext;
var website;
var listItems;
var usrLogname;
var regionName;
var regNm;

function hideQuicklinks()
{
    clientContext = SP.ClientContext.get_current();
    website = clientContext.get_web();
    currentUser = clientContext.get_web().get_currentUser();
    clientContext.load(currentUser);
    clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded), Function.createDelegate(this,this.onQueryFailed));

}

function onQuerySucceeded(sender, args)
{
    var index = currentUser.get_loginName().indexOf('|') + 1;
    var User = currentUser.get_loginName().substring(index);
    //alert("Name: "+ currentUser.get_title()+" LoginName: "+currentUser.get_loginName());
    //alert("Login: "+User.toString());
    checkRegion(User.toString());

}

function onQueryFailed(sender, args)
{
     alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}


function checkRegion(usrInfo)
{

    var clientContext = SP.ClientContext.get_current();
    var web = clientContext.get_web();
    var list = web.get_lists().getByTitle("Profile");
    usrLogname = usrInfo.toString();
    var camlQuery = new SP.CamlQuery();
    var que = "<View><Query><Where><Eq><FieldRef Name='LoginName' /><Value Type='Text'>"+usrInfo.toString()+"</Value></Eq></Where></Query></View>";
    camlQuery.set_viewXml(que);
    listItems = list.getItems(camlQuery);   
    clientContext.load(listItems);
    clientContext.executeQueryAsync(Function.createDelegate(this,this.onItemsLoadSuccess), Function.createDelegate(this,this.onItemsLoadFailed));

}

function onItemsLoadSuccess(sender, args)
{

    var listItemEnumerator = listItems.getEnumerator();
    var flag = 0;
    var oListItem;

     while (listItemEnumerator.moveNext()) 
     {
         oListItem = listItemEnumerator.get_current();      
         var logname = oListItem.get_item("LoginName").toString();
         if(usrLogname.toString() == logname.toLowerCase().toString())
         {      
            regionName = oListItem.get_item("Region").get_lookupValue();
         // alert("region "+logname.toLowerCase().toString()+" Name: "+usrLogname.toString());
        //  alert("Region "+ oListItem.get_item("Region").get_lookupValue());       
            flag = 1;
            break;
         }
     }
     if(flag==1)
     {
     // alert("Region name "+regionName.toString());
        getQuickLink(regionName.toString());
     }

}

function onItemsLoadFailed(sender, args)
{
     alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}


function getQuickLink(regionNm)
{

    var clientContext = SP.ClientContext.get_current();
    var web = clientContext.get_web();
    var list = web.get_lists().getByTitle("ExternalLinks");
    regNm = regionNm.toString();

    if(regionNm.toString()=="India")
    {
        angCall();

    }


}

function angCall()
{

        var myAngApp = angular.module('SharePointAngApp');  
        myAngApp.controller('spCustomerController', function ($scope, $http) {  
        $http({  
            method: 'GET',  
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('ExternalLinks')/items?$select=Title,URL&$filter=((Region eq 'India') and (IsActive eq '1'))&$orderby=Order0 asc",
            headers: { "Accept": "application/json;odata=verbose" }  
        }).success(function (data, status, headers, config) {  
            $scope.customers = data.d.results;  
        }).error(function (data, status, headers, config) {  

        });  
        }); 

}
  • Can you post the code in your question as well? – Ransher Singh Jul 21 '15 at 14:12
1

Using document.ready in sharepoint is useless. It doesn't promise that sp.js is there.

Try using this:

 SP.SOD.executeFunc('sp.js', 'SP.ClientContext', hideQuicklinks);

instead of

jQuery(document).ready( function () {
    SP.SOD.executeOrDelayUntilScriptLoaded(hideQuicklinks, 'sp.js'); 
});

If you want to do something at "sharepointready" then use

_spBodyOnLoadFunctionNames.push("nameOfYourFunction");

http://www.stephanrocks.com/2011/10/05/_spbodyonloadfunctionnames-in-sharepoint-vs-jquerys-document-ready/

  • Thanks, but it is not working either.. – Niranjan Kulkarni Jul 21 '15 at 14:50
  • My AngularJS is throwing the error, it is not getting that ng-app "SharePointAngApp" on the master page. I have passed id instead of ng-app as I had to implement the multiple modules on one single page. – Niranjan Kulkarni Jul 21 '15 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.