I am building a new project in ASP.NET MVC integrated with the Angular 5 framework with the help of VS.NET 2017.
I was following this article https://juristr.com/blog/2018/01/ng-app-runtime-config/ to implement the environment based configuration.
I am new to angular framework. This article is saying to add some environment key-value pairs to the .angular-cli.json file. But my project does not have this file.
Now my doubt is where do i place this below code logic :-
{
"apps":[
...
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"staging": "environments/environment.staging.ts",
"prod": "environments/environment.prod.ts"
}
]
}
Please suggest.
This is because you are not using angular-cli.
Install angular-cli using the following command on the terminal
npm install -g #angular/cli
Because you are not using angular cli you will have to add several packages and dependencies manually in the package.json file.
I'm used to building ng applications using just Angular and with this typical structure:
app
js
home
home.controller.js
home.directive.js
shared
usedByAll.controller.js
usedByAll.directive.js
templates
home.html
test
e2e
protractor tests
node_modules
index.html
package.json
So that when someone else coming in wants to catch up they just need to run
npm install
to install all the dependencies listed into their node_modules folder saving them time.
But recently I've started working on a Ruby-on-Rails project that is looking to angularize some of its components. This naturally means they're following their own MVC style and project structure and the angular stuff has been restricted to the following folders:
app/assets/javascripts/angular-components/component1
component2
component3
lib/angular.js
angular-mocks.js
etc
This is fine for development but when it comes down to testing I think this could be a problem. So my questions are really the following:
1 - When installing new modules via npm and attempting to save them as devDependencies
npm install karma --save-dev
to the package.json file, doesn't it mean you should have the node_modules folder at the root as well as the package.json file at the root?
2 - Should the karma.conf.js file, like the node_modules folder and package.json file, always be at the absolute root of the application?
Thanks
In many rails/angular applications you can see that Angular is tucked away inside the app/assets/javascripts folder. I personally don't like mixing and matching what I'm using when it comes to pages - i.e. go and get a Rails generated view or this one is an Angular one so go there.
Instead I broke out the two. Essentially the Rails part of this just functions as an API whereas Angular now handles the front end entirely. This allows you to treat the angular part nearly as a standalone app, following the typical angular structure. By doing this you can have the karma.conf.js file at the root of this folder.
ExampleAppName
- app (All Angular stuff is in here)
- src
- gulpfile.js
- karma.conf.js
- package.json
- api (All rails stuff is in here)
- rails stuff
i currently installed laravel and trying to create my first app, however when i required the laravel collective i get error above.
here is my composer.json
{
"require": {
"laravel/installer": "~1.1",
"laravelcollective/html": "5.1.*"
}
}
and my app.php have these lines..
providers=>
...Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
Collective\Html\HtmlServiceProvider::class,
aliases=>
...'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
i've been reading and searching for solutions but currently they never worked for me.. any help will be appreciated.. thanks in advance..
UPDATE
this is my cmd as of now..
u have to use php artisan serve inside your project folder. not inside composer folder.
for eg, laravel is my project folder inside www directory,
so, f:/wamp/www/laravel> php artisan serve
Here are the steps I took to install it in my app in Laravel 5.1.
I would suggest you delete the vendor folder for this from your vendor files and remove that line from your composer.json file to start from scratch.
First, require the package:
composer require "illuminate/html":"5.0.*"
Next, add it to your providers:
'providers' => [
...
'Illuminate\Html\HtmlServiceProvider',
],
Finally, add it to your aliases:
'aliases' => [
...
'Form'=> 'Illuminate\Html\FormFacade',
'HTML'=> 'Illuminate\Html\HtmlFacade',
],
You can check to see if it has worked by doing the following:
1) php artisan tinker
2) > Form::text('foo')
Which should output "<input name=\"foo\" type=\"text\">"
It seems like you have installed the HTML package and you are trying to use it in your "old" laravel app.
If you install a new app using the composer it should work fine, but if you are trying to use it in your "old" app that you created before installing the form/html collective try to download the files and copy the files in the src folder to the config folder in your app and you are good to go.
I am trying to add a custom Cordova plugin for the iOS platform, and I am having some issues when I compare that with the process to add a plugin on cordova.
The plugin I am trying to use here is https://github.com/phonegap-build/StatusBarPlugin
With cordova I used to simply use the command line cordova plugin add com.phonegap.plugin.statusbar
First, I tried to modify in native folder, but I noticed that If I do so, It works but It will be erased the next time I deploy again for iOS platform.
Second, I tried to add files (plugin js file and cordova_plugins.js file.) under apps/myapp/iphone, or apps/myapp/common, but this causes an issue : The cordova_plugins.js file format seems to become not ok.
Instead of having this working format:
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
"file": "plugins/org.apache.cordova.battery-status/www/battery.js",
"id": "org.apache.cordova.battery-status.battery",
"clobbers": [
"navigator.battery"
]
},
,
{
"file": "plugins/com.phonegap.plugin.statusbar/www/statusbar.js",
"id": "com.phonegap.plugin.statusbar.statusbar",
"clobbers": [
"window.StatusBar"
]
}
]
});
It have this format that does not work properly :
/* JavaScript content from worklight/cordova_plugins.js in JS Resources */
/*
* Licensed Materials - Property of IBM
* 5725-I43 (C) Copyright IBM Corp. 2006, 2013. All Rights Reserved.
* US Government Users Restricted Rights - Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*/
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
"file": "plugins/org.apache.cordova.battery-status/www/battery.js",
"id": "org.apache.cordova.battery-status.battery",
"clobbers": [
"navigator.battery"
]
}
]
});
/* JavaScript content from worklight/cordova_plugins.js in folder common */
/* JavaScript content from worklight/cordova_plugins.js in JS Resources */
/*
* Licensed Materials - Property of IBM
* 5725-I43 (C) Copyright IBM Corp. 2006, 2013. All Rights Reserved.
* US Government Users Restricted Rights - Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*/
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
"file": "plugins/org.apache.cordova.battery-status/www/battery.js",
"id": "org.apache.cordova.battery-status.battery",
"clobbers": [
"navigator.battery"
]
},
{
"file": "plugins/com.phonegap.plugin.statusbar/www/statusbar.js",
"id": "com.phonegap.plugin.statusbar.statusbar",
"clobbers": [
"window.StatusBar"
]
}
]
});
How should I do? Where should I put these file?
What is the proper way to add this custom plugin, especially if I want to add it only for iOS and not for Android?
UPDATE: As of MobileFirst 7.1, the SDK is now available as a Cordova plugin.
For those interested in adding 3rd party plugins to their MobileFirst (Worklight) projects I have described my own approach to installing them below, pending a feature release from IBM.
The concept is essentially:
create a Cordova project,
add the desired plugin,
create a MobileFirst project,
copy the plugin files from both projects to a staging area (so we can easily identify them),
merge the config.xml and cordova_plugin.js files (i.e. supplement the MobileFirst files with the plugin information from the Cordova project) and
copy the staged and modified files to MobileFirst.
Disclaimer: as per the accepted answer, IBM do not support/advise modifying the cordova_plugin.js file.
Firstly we need to create the Cordova project (plus the plugin) and MobileFirst projects (steps 1-4). I've used the Ionic Keyboard plugin as an example, needless to say this approach (creating a Cordova project and merging files) works for any supported plugin and target.
## Create a directory to contain your MobileFirst project e.g. mkdir example; cd example; ##
## Create Cordova project ##
mkdir .tmp
cd .tmp/
cordova create plugins com.plugins plugins;
cd plugins/
cordova platform add ios;
cordova plugin add com.ionic.keyboard;
cd ../..
## Create mobile first project ##
mfp create hybrid
cd hybrid/
mfp add hybrid hybrid
mfp add environment iphone
## Generate native files ##
mfp build
cd ..
## Create staging ##
mkdir -p plugins/native/www/default/worklight
mkdir -p plugins/resources/mobilefirst/
mkdir -p plugins/resources/cordova/
mkdir -p plugins/hm/
## Copy config.xml ##
cp hybrid/apps/hybrid/iphone/native/config.xml plugins/resources/mobilefirst/
cp .tmp/plugins/platforms/ios/plugins/config.xml plugins/resources/cordova/
## Copy Cordova files ##
cp -R hybrid/apps/hybrid/iphone/native/www/default/worklight/ plugins/resources/mobilefirst/
## Copy plugins JS ##
cp -R .tmp/plugins/platforms/ios/www/plugins plugins/native/www/default/worklight/
cp -R .tmp/plugins/platforms/ios/www/ plugins/resources/cordova/
## Copy classes ##
cp -R .tmp/plugins/platforms/ios/Plugins/Plugins/com.ionic.keyboard/ plugins/hm/
## Delete the Cordova project as we have copied all of the artefacts we need ##
rm -R .tmp
## Create the config and cordova_plugin.js which is going to override the mfp build version ##
cp plugins/resources/mobilefirst/config.xml plugins/native/
cp plugins/resources/mobilefirst/cordova_plugins.js plugins/native/www/default/worklight/
The staged config.xml and cordova_plugins.js files are now ready to merge (step 5).
Open the plugins/resources/cordova/config.xml file and copy the feature into the plugins/native/config.xml file.
<feature name="Keyboard">
<param name="ios-package" onload="true" value="IonicKeyboard" />
</feature>
Open the plugins/resources/cordova/cordova_plugins.js file and copy the plugin object into the plugins/native/www/default/worklight/cordova_plugins.js file.
{
"file": "plugins/com.ionic.keyboard/www/keyboard.js",
"id": "com.ionic.keyboard.keyboard",
"clobbers": [
"cordova.plugins.Keyboard"
]
}
Now we are ready to copy the merged files into the MobileFirst project (step 6a).
## Copy from staging to Worklight ##
cp -R plugins/hm/ hybrid/apps/hybrid/iphone/native/Classes/
The first time you copy the files Xcode won't pickup the new classes automatically, so open up the project in Xcode and right click on Classes and 'Add files to ...'. Add the files displayed in the dialog.
Finally, we can copy the files from the plugins/native directory into the MobileFirst project (step 6b). Unfortunately we need to copy this directory after every mfp build, as mfp resets the cordova_plugins.js file each time.
## Do this after every mfp build ##
rm -f hybrid/apps/hybrid/iphone/native/www/default/worklight/cordova_plugins.js
cp -R plugins/native/ hybrid/apps/hybrid/iphone/native/
Once complete, add the client code to your hybrid application and test (don't forget to run step 6 again after the mfp build) e.g.
<input type="text">
window.addEventListener('native.keyboardshow', keyboardShowHandler);
function keyboardShowHandler(e){
alert('Keyboard height is: ' + e.keyboardHeight);
}
I hope this guide proves useful. I use this process on a daily basis (albeit as part of Grunt) and look forward to a feature release from IBM.
Worklight 6.1.0.x does not yet support adding pre-made Cordova 3.x plug-ins using plugman or any other procedure you would do in a pure Cordova application, including trying to edit the file you're trying to edit. This is a known limitation in current versions of Worklight.
What I would do is read the training material of creating Cordova plug-ins in Worklight, and then take the source of the plug-in you want to add and copy it over.
There are probably other ways to do it, but none is convenient at this time.
There is a issue with the above mentioned solution by Chris. The plugin would surely work if you follow the process correctly but there will be severe consequences later. E.g Since the plugins folder and the cordova_plugins.js file will be overwritten everytime there is a mfp build, the wlapp files generated will never have the plugin code added. Hence if you are using direct update your code will be overwritten once you upload this wlapp file and the plugin would stop working.
i have kept the zf2 library inside vendor folder as follows . How to define composer to set zf2 updated through composer?
If you want it to be managed by Composer, remove your existing vendor folder and have Composer set it up again. See the ZF skeleton application for an example of adding ZF2 to your composer.json.