javascript - How to configure an AngularJS App using configuration blocks? -
i´m trying configure angularjs app. after searching found this idea @ official angularjs.com page. seems pretty way configure application before it´s runtime. in case want read in few parameters , path-values simple .xml, .properties
or comparable using javascript in configure block. have no clue neither how implement idea using concept nor if way solve problem configuring app using external file.
for better demonstration build simple app working base. in end want configure values of config.path.base
, config.path.rest
external file.
i´m pretty sure guys out there able me.
so here pretty simple code:
'use strict'; var app = angular.module('configtestapp', []); var config = config || {}; config.path = { base: "localhost:8080", rest: "/sample/api/rest" } app.controller('showconfigcontroller', ['$scope', function($scope){ var vm = this; vm.greeting = "basic configuration"; vm.basepath = config.path.base; vm.restpath = config.path.rest; var d = new date(); vm.timestamp = d.gettime(); }]);
<!doctype html> <!--[if lt ie 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> <!--[if ie 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> <!--[if ie 8]> <html class="no-js lt-ie9"> <![endif]--> <!--[if gt ie 8]><!--> <html class="no-js"> <!--<![endif]--> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <title>htmlfrontendbase</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width"> </head> <body data-ng-app="configtestapp" class="indexpage"> <div ng-controller="showconfigcontroller showconfctrl"> <h1>{{showconfctrl.greeting}}</h1> basepath: {{showconfctrl.basepath}}<br/> restpath: {{showconfctrl.restpath}}<br/> timestamp: {{showconfctrl.timestamp}}<br/> </div> <!-- configurations , constants --> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> </body> </html>
edit:
application running on tomcat server single initial configuration.
Comments
Post a Comment