Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
I made function ( like class )
Ex Code )
Use ModelInfo )
I Made Many Views
I must Copy ModelInfo Function when i make view
Is there any other way?
like include in c++
Hi @wxywxy1 ,
you can save your file as js file in the project directory (e.g. upload folder) and load it from here as mention in the post Include Java Script Dokuments
as further info you can use some function as the exmaple below "loadjscssfile"
Here in the example I copied both files /uploaded them (style.css and test.js) to the Upload resource folder (app/resources/Uploaded)
Then I used the following code for a definition of function which should be called from e.g. from button or on modelload event. The function will change the apperance of the widget Icon according to the definition of style.css /it will override a style definition) and will load the test.js libary so that all funciton definition are afterwords available in my code. Also it could ovrride some available function definition if there is name confilict...
$rootScope.$on('modelLoaded', function() {
$scope.testLoad();
});
...
$scope.testLoad= function()
{
$scope.loadjscssfile("app/resources/Uploaded/style.css", "css")
$scope.loadjscssfile("app/resources/Uploaded/test.js", "js")
}
//--------------------------------------------------------
//this is utility function to load the style or javaScript
//--------------------------------------------------------
$scope.loadjscssfile= function(filename, filetype){
if (filetype=="js"){ //if filename is a external JavaScript file
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src", filename)
}
else if (filetype=="css"){ //if filename is an external CSS file
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
if (typeof fileref!="undefined")
document.getElementsByTagName("head")[0].appendChild(fileref)
}
...
Thank for Reply
Other Question
ex code )
Yes, you do not need to load the code in such event. I oftern use this because I wnat to ensure that all widget are already loaded. Often I use also : $scope.$on('$ionicView.afterEnter', function() { ... or $scope.$on('$ionicView.beforeEnter', function() {...
but you can write simple your function as first in the Home.js (or your <startView>>.js) and this will be loaded , I think early enough. At least, I do not find a reason why this should not be early enough
but... I think there is a file where you can specify some libraries for loading :
<project folder>\extensions\runtimeExtensions.js
you can save a backup of this file and save your *.js file in the extensions/js folder and add it in the runtimeExtension.json file as runtimeLibaries.
I did not test this now but I could remember that I sued it one time in the past long time ago and it was working.
Thank for Reply
( runtimeExtensions.json File )
Hi @wxywxy1 ,
did you stop studio first? The overriding of the file happened when you change some of the studio setting but studio is still running. I think it should work so far, I remember but sure I could test it more deeply.
Could you suggest a sample library where I could test – just to be sure that this has a relevance for your case.
thank for replay
LoadModule.zip
Can you make sample ( as import runtimeLibaries ) , using LoadModule Source ?
I want to find a way.
Is this impossible?