Visualforce-Angular 6:未从静态资源检索资产/i18n/en.json文件

时间:2019-02-12 07:09:51

标签: salesforce angular6 visualforce

我们已经构建了Angular 6应用,正在尝试使用visualforce页面(Salesforce)进行调用。

我们为'dist'文件夹创建了静态资源,并在vf页面中包含了js文件。

一切正常,除了: 我们正在使用存储在'/assets/i18n/en.json'文件中的翻译,Angular的main.js文件会自动请求加载en.json翻译。

这在localhost上工作正常,但是当我们在vf页面中尝试相同时,会出现错误:

SyntaxError:JSON中意外的令牌<在XMLHttpRequest.u(https://c.cs111.visual.force.com/resource/1549953043000/test_map/main.js上JSON.parse()↵的位置2 position处。

我们尝试显式加载en.json文件,但不起作用。 尝试重命名资产文件夹。

<apex:page controller="AngularDemoController" sidebar="false">
<apex:variable value="{!IF($CurrentPage.Parameters.local == 'true','https://localhost:4200',URLFOR($Resource.test_map))}"
               var="resourceURL"/>
<app-root id="app"></app-root>
<script>
    var Visualforce = Visualforce;
    var resourceURL = '{!resourceURL}';

    function salesForceCallbackForSave(event) {
        console.log('Js event callback', event);
        const promise = new $.Deferred;
        setTimeout(function () {
            // promise.reject({message: 'This is salesforce message'})
            promise.resolve()
        });
        return promise
    }

    const data = {
        preSelectedAddress: "Westlock County, AB, CA,",
        latitude: "58.859223547066584",
        longitude: "-102.48046875",
        userName: "Shivshankar Alkondwar",
        isSandbox: true
    };
    let input = document.getElementById("app");
    const dataString = JSON.stringify(data);
    input.setAttribute('pluginSetting', dataString);
    input.setAttribute('useAsSalesForcePlugin', 'true')
</script>
<apex:includeScript value="{!resourceURL + '/runtime.js'}"/>
<apex:includeScript value="{!resourceURL + '/polyfills.js'}"/>
<apex:includeScript value="{!resourceURL + '/styles.js'}"/>
<apex:includeScript value="{!resourceURL + '/scripts.js'}"/>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.2.1/mapbox.css' rel='stylesheet'/>
<link href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" rel="stylesheet"/>
<script src="{!resourceURL + '/main.js'}" type="text/javascript"></script>
<apex:includeScript value="{!resourceURL + '/2.js'}"/>
<apex:includeScript value="{!resourceURL + '/3.js'}"/>
<apex:includeScript value="{!resourceURL + '/7.js'}"/>
<apex:includeScript value="{!resourceURL + '/8.js'}"/>
<apex:includeScript value="{!resourceURL + '/9.js'}"/>
<apex:includeScript value="{!resourceURL + '/10.js'}"/>
<apex:includeScript value="{!resourceURL + '/11.js'}"/>
<apex:includeScript value="{!resourceURL + '/common.js'}"/>


<!--<apex:includeScript value="{!resourceURL + '/assets/i18n/en.json'}" />-->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"
      type="text/css"/>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" type="text/css"/>
</apex:page>

0 个答案:

没有答案