Integration of angular 10 with existing PHP project - javascript

I have PHP project with having AngularJs plugins. I am migrating them to angular 10. It has functions implemented at PHP project controllers which has mechanism to load script files as below.
public function getJsFiles(&$jsFiles)
{
$jsFiles[] = "angular-plugins/dist/runtime.js";
$jsFiles[] = "angular-plugins/dist/polyfills.js";
$jsFiles[] = "angular-plugins/dist/styles.js";
$jsFiles[] = "angular-plugins/dist/vendor.js";
$jsFiles[] = "angular-plugins/dist/main.js";
}
So, I have create root level NG10 project & migrated few components in few modules and successfully integrated with single build files(main.js, polyfills.js, vendors.js,runtime.js, styles.js) mentioned above.
Project has functionality that when user disable that module it won't load relevant Js files on the page.
So Problem here is, to fulfil that I have generated module wise chunk files with lazy loading (e.g core-home.js, multisites.js), But when I try to integrate with PHP project, neither it's loading component on the page not giving any console errors.
Our main goal is to load project with PHP, anguarJs and angular 10 all together.
Note : Project runs on wamp server. Please check below image for folder structure & files loaded on PHP file.
project-structure
Thanks in advance.

Related

How can we integrate Vue JS with ASP.NET MVC and nuget packages

How can we integrate Vue JS with MVC Project that is existing and using with Nuget Package.
Tried with below approach.
<h3>VueJS 2 in ASP.NET MVC 5</h3>
<div id="aboutPage">
{ { message }}
</div>
<script>
var aboutPage = new Vue({
el: '#aboutPage',
data: {
message: 'Hello Vue! in About Page'
}
});
</script>
Question:
Is there need for any additional package like - webpack or gulp, we already have bundle config of MVC?
2.
How can we create separate files or design for each view like:
To separate the service call (to call web api from client side)
separate out the template file.
methods or logic to write in JS.
any example for MVC with VueJS like - controller, view,service, vue JS file is great..
Thanks a lot !
You can use vuejs buy adding it to your layout.
#Scripts.Render("~/node_modules/vue/dist/vue.min.js")
You need to install Nodejs on your machine to use NPM and ES6 features.
For integrate Vue.js in .NET MVC you need module bundler (webpack, gulp),can choose one of this options, the popular is webpack:
1:(Gulp, Browserify), which has some limitations such as supporting only require syntax handling assets. and the setup is kind of complicated.
2:(Webpack), which has a lot of cool things you can do with it, Hot Reload. check this repo
by using webpack, you config it to handle just js files and it will handle js files for build too , upon build each entry will be copied inside Scripts/bundle, also you need some loaders such ass (vue, scss, css and js) for webpack. check this
Webpack uses webpack-dev-server for development which is basically a node.js based server which serves assets (javascript, css etc) that our browsers can interpret. Usually these assets include some development friendly features like Hot Reload. These assets are not minified and are quite different from the ones generated when building for production.
devServer: {
proxy: {
'*': {
target: 'http://localhost:5001',
changeOrigin: true
}
}
},
webpack-dev-server has a feature which can proxy requests from one url to another. In this case, every request from "webpack dev server " will be proxied to your "asp.mvc server". So, if we run our MVC app on http://localhost:5001 and run npm run dev , on port 8086 you should see the same output as from our MVC app.
Answers:
1: yes you have to setup Webpack or Gulp.
2. by using webpack you can all thing for file structuer that you want
check this tree
-app
--libs
----utils
----components
---------commons
---------.......
-----pages
---------.....
check this articles
https://medium.com/corebuild-software/vue-js-and-net-mvc-b5cede228626
http://www.lambdatwist.com/dot-net-vuejs/
If you want to keep the .cshtml files and use MVC as a multipage application, you can take a look at this template as an example or starting point. https://github.com/danijelh/aspnetcore-vue-typescript-template
You can create modules of pages which you want to enhance with Vue and import that bundle.

Angular 2 - TypeScript File not resolving to .js extension .NET MVC Application

Background
I am migrating one of the apps from Angularjs 1.x to Angular 2. Being new to the Angular 2 , I am first trying to get grasp of different files used for configuration
Before jumping to my app, I created a small dummy app with the help of quickstart files from Angular Quickstart on gitub
https://guthub.com/angular/quickstart
I move those files into a .NET MVc 5.0 web app. When I build the app using the npm CLI
npm start
It creates an index.htm, and that successfully ran. My next step was to use a MVC View instead of this index.htm, This time, I created a default route for localhost/ pointing to PublicController with a view Index.cshtml.
Problem Statement
While using MVC views, routed through Controllers, what I see is that main.ts file when compiled omits the file extension - *.js For e.g.
import { AppComponent } from './app.component';
in my Main.ts, when compiled translates to (in main.ts)
var app_component_1 = require("./app.component");
My page ran with a console error, and I saw 404 error for not been able to resolve app.component.
All works out fine, If I manually type in .js in my main.js file. But that's not the solution.
var app_component_1 = require("./app.component.js");
Question
Which setting should I change and which file that should resolve filename in the main.ts to filename.js
Finally, found the solution.. problem is with the dot in the file name , Issue is reported here too https://github.com/systemjs/systemjs/issues/756
I added the following setting in the systemjs.config file
packages: {
'.': {
defaultExtension: 'js'
},

How to create an AngularCli application that contains another AngularCli inside?

I have an application in development that is in Angular2 using AngularCli, and I want to use it as a "Layout" (like a MasterPage) to another project. Like a big "SPA System".
For example, in the menu we will have the following:
Framework
Page A
Xpto
Page B
The Framework is running in http://localhost:90 and XPTO is running in http://localhost:91. Both of them is running on AngularCli.
I want to create a structure that when I click on Page A or Page B, the browser doesn't reload and it will give an "app" style to the user, loading the page as a SPA ACROSS the sites.
The main reason is to reuse the Javascripts, CSS and many other files from de "Framework" project to other 20 projects. I don't want to replicate all the components, files and etc across those projects.
Today we use MVC3 and the RazorGenerator to create .cshtml as a DLL to reuse the .cshtml from Framework to other modules.
But we want go AngularCli. Is there any way to do that ? If it isn't, is there some way to create a template in AngularCli that can be reused the components and the other files ?
Thank you !
You can put shared Angular components and modules into a separate npm package and use this package as a dependency for other projects.
In order to reference your npm package (I assume it's not hosted at npmjs.com) you can specify a git repository or local path.
Here is an example of package.json
{
"name": "foo",
"version": "0.0.0",
"dependencies": {
"my_git_package": "git+ssh://user#hostname/project.git#commit-ish",
"my_local_package": "file:../foo/bar"
}
}
Take a look at dependencies section here https://docs.npmjs.com/files/package.json

Multilingual App in Angularjs or in Ionic Framework

I am very new to both Angularjs and Ionic Framework. I coming from Microsoft background.
I am trying to make app in 3 languages (English, Arabic and French). As I told you that I am coming from Microsoft background I am thinking in .net way that for multilingual apps translation we use resource file and in our .net code as per language environment. As for example
http://www.codeproject.com/Tips/580043/How-to-make-a-multi-language-application-in-Csharp
Is there any way to do same thing Angularjs or Ionic Framework
Follow the steps here:
Download the Source Code.zip file from here and copy the angular-translate and angular-translate.min file to www/lib/ionic/js/angular folder along with other js files.
In index.html, include "http://lib/ionic/js/angular/angular-translate.js"
along with other script tags.
Now you need to add 'pascalprecht.translate' in dependency list of controllers.js file like,
angular.module('starter.controllers', ['pascalprecht.translate']). You can also add it in dependency list of main module.
Create a sub-folder, for example, 'lang' within www and add js files for each language you want to add to your application. Within individual JavaScript files, create an array variable containing key-value mapping of all translations. For example, in english.js file:
var translations_en = {
Title:'My app title',
Settings:'Settings'
}
In bengali.js file:
var translations_bng={
Title:'অ্যাপের নাম',
Settings: 'সেটিংস'
}
Note here, the key names will be same in all files but values will be different. In your HTML, you will access the value through the key. Similarly, you can add multiple language in multiple files.
Now, in your app.js, add the following code.If you already have some other .config functions in your app.js, No worries! You can have more than one .config functions. Add this separately, better.
.config(function($translateProvider) {
$translateProvider.translations('en', translations_en);
$translateProvider.translations('bng', translations_bng);
$translateProvider.preferredLanguage('en');
}
You can show values like this, {{'Title'|translate}}. Depending on the preferredLanguage given, in place of 'Title', appropriate value declared in js file of 'lang' folder will be shown here.
For more details, visit this blogpost
I have create a library for translate angular and ionic app.
You can install with bower:
bower install ng-translator --save
or with npm
npm install ng-translator --save
Check out this

Requiring external JavaScript file

After reading all the relevant answers in SO and posts in the Appcelerator forums I still can't get this to work:
I have an application developed in Appcelerator, and I want to load an external JavaScript file in some of my controllers.
My App structure is as follows:
+ app
- assets
- controllers
- models
+ lib
- IndicatorWindow.js
...
Inside a controller I have the following code:
var uie = require('lib/IndicatorWindow');
But when I run this on an Android phone I get:
Uncaught Error: Requested module not found: lib/IndicatorWindow
I have also tried placing the lib folder outside of app, and using other paths such as /lib/IndicatorWindow and app/lib/IndicatorWindow.
I even tried using Ti.include() instead, with the same result. But I would rather use require() since I prefer using CommonJS modules.
Make a lib folder inside assets folder and paste the js file there and you would be able to require file just like you do in classic :)
Thanks
just use var uie = require('IndicatorWindow');
Also make sure it uses exports inside the JS

Categories