Comments (11)
@Jvogel-Amplify ... which you can for sure read (together with code examples) on my github: https://github.com/arcadeJHS/AngularVueIntegration.
Hope it helps!
from ngvue.
You can use the slot element in the vue template, however, the implementation is buggy and it seems like they are considering deprecating it.
I am also in the same boat as you, we're trying to migrate our angular app to vue and having the ability to have angular directives/components within a vue component is necessary.
I've found that you cannot have any whitespace between your vue component tags and the slot content. Your angular code cannot have any translcudes and there are some other buggy behaviours that I'm trying to work around atm.
E.g., Your example would have to be written as:
<old-angular-app>
<ng-vue-component><old-existing-angular-component /></ng-vue-component>
</old-angular-app>
from ngvue.
Thank you for the suggestion @jaredmcateer!
I've found the buggy implementation mentioned in the issue #57.
At this point I am not sure if following this way (trying slots) it's a "good" choice... but still, as you, I have the necessity to keep angular code inside vue while migrating.
from ngvue.
I'm sorry but as you said, ngVue
was not designed to allow AngularJS components to be rendered inside VueJS components. We've tried to add slots
but it doesn't work in multiple situations: #66, due to the difference of rendering mechanism between AngularJS and Vue components.
However, you could compile an AngularJS component template within mounted()
hook for example, inside your Vue component, and add the compiled element to the current element (this.$el
):
mounted() {
const template = `<custom-ng-tag foo="$ctrl.foo"></custom-ng-tag>`;
const bindings = { foo: this.foo };
const scope = angular.extend($rootScope.$new(), { $ctrl: bindings });
const element = $compile(template)(scope);
this.$el.append(element[0]);
}
This should kinda work but this is very experimental, imho. I would advise not to use it in production 😅
from ngvue.
Thank you @nicolaspayot!
I will experiment a little bit... as I said, I would prefer to preserve part on the existing angular code in a new Vue wrapper, and my main concern is how to handle the $scope in the existing angular code (which is quite pervasive and entangled into the application... ugly as it was...)!
from ngvue.
@nicolaspayot: I am sorry, but I have a couple of (maybe stupid) question!
-
It seems to me that using an angular component through slot seems to work in a "normal" template, but does not work when loading a component via vue-router. Is it right?
-
In your example here above, how are you using $rootScope (and $compile)? It seems you are using it as a global object, but that should not be available there. Anyway, so far I got it working with a slightly different version:
mounted() {
const el = angular.element(this.$el);
el.injector().invoke(['$compile', '$rootScope', function($compile, $rootScope) {
const scope = angular.extend($rootScope.$new(), {});
$compile(el)(scope);
}]);
}
Well... working... kind of... :-P
from ngvue.
I've come to this "AngularComponent.vue" component:
<template>
<div></div>
</template>
<script>
export default {
name: "AngularComponent",
props: ['component'],
mounted () {
const el = angular.element(this.$el);
const componentTemplate = this.component.template;
const componentCtrl = this.component.$ctrl;
el.injector().invoke(['$compile', '$rootScope', function($compile, $rootScope) {
const scope = angular.extend($rootScope.$new(), {$ctrl: componentCtrl});
el.append($compile(componentTemplate)(scope));
}]);
}
};
</script>
Inside a Vue component, to include an Angular component, I use it in this way:
<template>
<div>
<angular-component :component="angularComponent"></angular-component>
<div>Vue template</div>
</div>
</template>
<script>
import AngularComponent from './components/AngularComponent';
export default {
name: "AngularInsideVue",
components: { AngularComponent },
data() {
return {
angularComponent: {
template: '<example-component some-param="$ctrl.someParam"></example-component>',
$ctrl: { someParam: 'Hello from Angular!' }
}
};
}
};
</script>
Still I need to test it with more complex angular components, bindings, and updates, but it seems to work.
from ngvue.
@arcadeJHS Did you ever get this working with bindings, updates, etc...? I have a similar use case as you
from ngvue.
@Jvogel-Amplify Well, I guess a sort of! :)
If you are interested in more details, I wrote on Medium a detailed review of that titled "Migrating an Angular 1.x app to Vue 2.x".
from ngvue.
This is a great guide thank you for documenting all of this! I am considering migrating an angular 1.x app to Vue so this will be a big help.
from ngvue.
@Jvogel-Amplify: no problem, thank you for reading! :-)
That, for sure, is my point of view... but I hope it helps.
from ngvue.
Related Issues (20)
- Support for composition api? HOT 2
- .sync modifier HOT 2
- Vue3 support HOT 6
- Support multiple children in <slot>
- How to listen to broadcasted event from angular components into Vue component? HOT 4
- Vue component not rendering on IE HOT 1
- Vue-apollo provider doesn't work
- How to use Vue.js provide/inject with ngVue?
- Quirk Mode doesn't work.
- Specify `module` to `build/index.esm.js` in `package.json` to support ESM import HOT 2
- Incorrect main/module/exports in `package.json` in v2.1.1 HOT 2
- Mount Vue in ShadowDOM HOT 1
- Plugins do not work with Webpack 5 HOT 4
- Time to remove that deprecation message? HOT 4
- Update to the Vuex store does not trigger update in the components in debug mode. HOT 2
- `this.$store` is undefined after migration to wepback5 HOT 8
- how to re render a vue component with ngVue HOT 3
- Error: ngVue components must have a parent tag or they will not render HOT 1
- Deprecation warning for camelCase event names cannot be suppressed HOT 5
- v-directive not updating value
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngvue.