Comments (9)
So found a quick solution to this, at least when it comes to passing plain text inside of the component references tags.
Wrap your plain text content in the template where you reference the component with <span></span>
tags. This will prevent the error from coming up, and cleanly pass the content through into the slot.
However, this still does not fix the issue where default content assigned into the slot does not appear, when not passed in from the template component reference.
Possible long term solution?
After playing around with the jsfiddle created by korya above, I think a workable solution to this might be to first wrap whatever contents is found in jqElement[0].innerHTML
with <span></span>
tags first, then run it through the compiler. The extraneous span tags can then be removed from the resulting HTML before it is injected into the DOM.
Reason:
This is caused by how AngularJS/jqLite processes bare strings without any wrapping tags around them.
It starts out with this line: https://github.com/ngVue/ngVue/blob/master/src/angular/ngVueLinker.js#L34, that attempts to have AngularJS $compile whatever the passed content is.
const html = $compile(jqElement[0].innerHTML)(scope)
This in turn is sent by Angular to the JQLite constructor, which attempts to parse it (from the angular.js file):
function JQLite(element) {
if (element instanceof JQLite) {
return element;
}
var argIsString;
if (isString(element)) {
element = trim(element);
argIsString = true; // <--- [DEBUG] This gets set to true
}
if (!(this instanceof JQLite)) {
// [DEBUG] As argIsString is true, and the first character is not '<'... it throws an error
if (argIsString && element.charAt(0) !== '<') {
throw jqLiteMinErr('nosel', 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element');
}
return new JQLite(element);
}
from ngvue.
I feel sorry that we will not fix this bug and <slot/>
has to be deprecated because your refactored code will get harder & harder to develop, test and debug.
With <slot/>
the vue components have to take care of the angular runtime and eventually those will be tightly coupled.
If you have to preserve the angular code in the vue components perhaps you could use web components as a bridge between these two runtimes :-)
from ngvue.
Update: Found kind of a workaround for this issue, see my follow up comment directly below this one.
Encountering this same issue where it appears the Vue slots are not supported by ngVue.
When setup in my dev env using webpack, the specific exception I receive is:
Error: [jqLite:nosel] Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element
https://errors.angularjs.org/1.7.4/jqLite/nosel
at angular.js:138
at JQLite (angular.js:3231)
at compile (angular.js:9602)
at Vue.rootProps.mounted (index.js:170)
at invokeWithErrorHandling (vue.runtime.esm.js:1854)
at callHook (vue.runtime.esm.js:4213)
at mountComponent (vue.runtime.esm.js:4080)
at Vue.push../node_modules/vue/dist/vue.runtime.esm.js.Vue.$mount (vue.runtime.esm.js:8409)
at Vue._init (vue.runtime.esm.js:5012)
at new Vue (vue.runtime.esm.js:5079)
My vue-button.vue file component is defined as:
<template>
<a class="button-primary" href="#" ><slot>Default Button Text</slot></a>
</template>
<script>
export default {
name: 'VueButtonComponent'
}
</script>
The component is referenced in my AngularJS template as:
<vue-button-component>This is a Vue Button</vue-button-component>
If I remove the <slot>Default Button Text</slot>``` from the template definition, and the
This is a Vue Button` from the component reference, I no longer get the exception - but that fails to provide Vue's slot implementation.
I am initializing my Angular app with ngVue, along with declaring the Vue component as follows:
import Vue from 'vue';
import 'ngVue';
import VueButtonComponent from './vue/vue-button.vue';
...
...
angular.module('myApp', [ngVue])
.directive('vueButtonComponent',
/* @ngInject */
createVueComponent => createVueComponent(Vue.component('vueButtonComponent', VueButtonComponent))
);
Versions used:
Angular: 1.7.4
Vue: 2.6.10
Vue-template-compiler: 2.6.10
Vue-loader: 15.7.0
ngVue: 1.6.0
from ngvue.
I'm sorry but 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.
We'll probably deprecate this experimental feature in a future release and remove it completely in the next major.
from ngvue.
@dorayx what do you think about this slot issue?
from ngvue.
So not sure if this is beating a dead horse, but my main issue was not directly related to injecting Angular compiled output into a Vue <slot></slot>
. I was simply trying to inject a hard coded string into the slot and it would cause that exception. Wrapping my string in a <span></span>
prevented the exception from occurring.
In my testing project, I am actually successfully using the following:
<my-custom-vue-component><span ng-translate="SYSTEM.TRANSLATION_KEY></span></my-custom-vue-component>
This works just fine, AngularJS is able to translate the string and inject it into the slot, span and all.
If deprecating this functionality will prevent that from working, then ngVue will be less useful for our purposes. I can see that trying to compile an entire AngularJS directive/component inside of the slot would be problematic, so if that is the reasoning then it's understandable.
from ngvue.
@nicolaspayot what do you think of it? Perhaps we need a list of slot-related caveats for developers and then fix this text-rendering issue only?
from ngvue.
@SmilingJoe your solution sounds good to fix the issue :-) and pr is welcomed
As you know, it becomes problematic to compile angular into a wrapped vue component and so slots will look buggy and confusing: some canβt be rendered while the others can :-( this functionality is a bit useless now.
from ngvue.
@dorayx well, we could totally render slots with simple texts and point out caveats for other use cases in the doc π
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
- Maintainers needed
- 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.