Coder Social home page Coder Social logo

Comments (3)

nicolaspayot avatar nicolaspayot commented on July 18, 2024 1

I don't understand how can <my-component /> be rendered correctly as self-closing tags for custom elements don't work with AngularJS. Here is a quote from Igor Minar:

self-closing or void elements as the html spec defines them are very special to the browser parser. you can't make your own, so for your custom elements you have to stick to non-void elements ().

this can't be changed in angular. closing.

angular/angular.js#1953 (comment)

I think it should work with $compile('<my-component></my-component>')($rootScope).html()

from ngvue.

pcable avatar pcable commented on July 18, 2024

Hi @nicolaspayot, Thanks for looking into this.

I guess it must be the browser that's permitting the use of the self closing tag (Chrome 72.0.3626).

I think it should work with $compile('<my-component></my-component>')($rootScope).html()

I've written some karma tests to show that it doesn't work without having a wrapper div regardless of self closing tags or not. This is different to the angular behavior which doesn't require the outer div

angular
    .module('test', ['ngVue'])
    .component('myAng', {
        template: "<span>Hello From Angular</span>"
    })
    .value('myVue', {
        template: "<span>Hello From Vue</span>"
    })
    .directive('myVue', function (createVueComponent) {
        return createVueComponent('myVue')
    })

describe('ngVue compilation', () => {

    var $compile;
    var $rootScope;
    
    beforeEach(() => {
        angular.mock.module('test');
        angular.mock.inject((_$compile_, _$rootScope_) => {
            $compile = _$compile_
            $rootScope = _$rootScope_
        })
    })

    it('Renders angular components with no wrapper', () => {
        var contentShort = $compile('<my-ang/>')($rootScope.$new());
        expect(contentShort.text()).toBe("Hello From Angular")

        var contentLong = $compile('<my-ang></my-ang>')($rootScope.$new());
        expect(contentLong.html()).toBe(contentShort.html())
    })
    
    it('Renders vue components with wrapper', () => {
        var contentShort = $compile('<div><my-vue/></div>')($rootScope.$new());
        expect(contentShort.text()).toBe("Hello From Vue")

        var contentLong = $compile('<div><my-vue></my-vue></div>')($rootScope.$new());
        expect(contentLong.html()).toBe(contentShort.html())
    })

    //THIS ONE FAILS!
    it('Renders vue components with no wrapper', () => {
        var contentLong = $compile('<my-vue></my-vue>')($rootScope.$new());
        expect(contentLong.text()).toBe("Hello From Vue")
    })

})

This could cause an issue for anyone who is trying to do a direct conversion from their angular components into vue (which is where I had the issue) and this request should save them a lot of trouble.

from ngvue.

nicolaspayot avatar nicolaspayot commented on July 18, 2024

Fixed with #85

from ngvue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.