我需要動態地在我的index.html
頁面中添加腳本,具體取決於應用程序版本。我有一個控制器,它返回應用程序版本,並試圖做到這一點使用angularjs:在角度加載前從服務器獲取腳本位置
var resourceLoader = angular.module('MyTabs', []);
resourceLoader.controller('ResourceLoaderController', ['$scope', '$http', function ($scope, $http) {
$scope.getVersion = function() {
$http.get('/version/get').then(function (response) {
$scope.version = response.data;
var link = document.createElement("link");
link.setAttribute("type", "text/css");
link.setAttribute("rel", "stylesheet");
link.setAttribute("href", '/r/' + $scope.version +'/css/app.css');
document.getElementsByTagName("head")[0].appendChild(link);
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.setAttribute("src", '/r/' + $scope.version +'/js/app.js');
document.getElementsByTagName("head")[0].appendChild(script);
});
};
$scope.getVersion();
}]);
它的工作原理,但有角控制器在app.js
,我在運行時AuthController
,在index.html
使用的,是不確定的得到一個錯誤。
有沒有什麼辦法從angularjs開始處理網頁之前從服務器獲取應用程序版本幷包含腳本?
你是什麼意思的應用程序版本?角? –
upvote for both questions,because you did not change [previous one](http://stackoverflow.com/questions/34433750/get-script-location-from-server)當發現下一個問題時。 –
應用程序版本是「/ version/get」返回的數字。 Angular - 是js框架(https://angularjs.org/) – Kirill