Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

$rootElement click handler traverses above all parents without finding root html element #1060

Closed
bkc opened this issue Jun 15, 2012 · 5 comments

Comments

@bkc
Copy link

bkc commented Jun 15, 2012

New in 1.0.0, when clicking a button embedded in a template, firebug throws this in firefox 13:

elm[0] is undefined
http://code.angularjs.org/1.0.0/angular-1.0.0.js
Line 5356

It looks like this comparison fails to match:

if (elm[0] === $rootElement[0]) return;

then on the next loop elm = []

adding a breakpoint at row 5356, elm is the following elements

button.btn
div.controls
div.control-group
div.span2
div.row
div.tabbable
div.ng-scope

Therefore it appears that div.ng-scope has no parent.

The actual parent of div.tabbable is a div with ng-form. But that div is a fragment loaded into the templateCache using this code

sfiTemplateLoader = angular.module('SFI.template-loader', [])

sfiTemplateLoader.directive 'sfiTemplateLoader', ($templateCache, $rootScope) ->
    return (scope, element, attrs) ->
    options = {}
    mydiv = $('<div />')
    templates = attrs.templates.split(' ')
    loaded_template_count = 0

    for template_path in templates 
        console.log "loading template file", template_path

        mydiv.load template_path, () ->
            # on callback, 'this' is the loaded dom element
            $(this).find('*[template-container]').each (index, element) ->
                template_name = $(element).attr('template-container')
                if template_name
                    html_data = $(element).clone().wrap('<div>').parent().html()      
                    $templateCache.put template_name, html_data
                    console.log('loaded template', template_name)

            loaded_template_count += 1
            if loaded_template_count >= templates.length
                $rootScope.$apply () ->
                    $rootScope.$broadcast 'sfiTemplateLoader', 
                        status:'loaded'
@pkozlowski-opensource
Copy link
Member

Having exactly the same issue on my side :-(

@bkc
Copy link
Author

bkc commented Jun 16, 2012

I skipped rc11 and rc12, btw, so maybe it is new in one of those releases

@IgorMinar
Copy link
Contributor

Can you guys create a plunk demonstrating the problem? The template is here: http://plunker.no.de/edit/from:2246015

thanks!

@IgorMinar
Copy link
Contributor

I reproduced this bug in this plunk: http://plunker.no.de/edit/qOTiRn?live=preview

simple check to verify that the parent exists should fix the problem.

@IgorMinar
Copy link
Contributor

This issue is a dupe of #1058

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants