LoginSignup
0
0

More than 5 years have passed since last update.

$A.componentService.newComponentAsyncが動作しない、改めうまく動いたよ

Last updated at Posted at 2014-12-18

$A.componentService.newComponentAsyncが動作しないですね・・・で、困ってる。

hoge.cmp
<aura:component>
    <ui:button aura:id="foobar" label="submit me!" press="{!c.doInit}" />
</aura:component>
hogeController.js
({
    doInit : function(component, event, helper) {
        console.log('clicked!');
        $A.componentService.newComponentAsync(
            this,
            function(newButton){
                newButton.addHandler('press',component,'c.doInit');
                var body = component.get('v.body');
                body.push(newButton);
            },
            {
                "componentDef": "markup:// ui:button",
                "localId":"myLocalId",
                "attributes" : {
                    "values":{"label":"Submit"}
                }
            }
        )
    },

})

うーんうーんと悩んでいたところ、@twk から「これでできるよ、ボケッ」というツッコミをもらいました。で見なおしてみたところ・・・
☓"markup:// ui:button" → ◎"markup://ui:button" 余計なスペースが入っているのを発見し、修正・・・で、結果、ちゃんと動作しました。

<aura:component>
    <ui:button aura:id="foobar" label="submit me!" press="{!c.doInit}" />
    <div aura:id="hogehoge"/>
</aura:component>
        $A.componentService.newComponentAsync(
            this,
            function(newButton){
                newButton.addHandler('press',component,'c.doInit');
                var c = component.get('hogehoge')
                console.log(c);
                c.set("v.body",newButton);
            },
            {
                "componentDef": "markup://ui:button",
                "localId":"myLocalId",
                "attributes" : {
                    "values":{"label":"Submit"}
                }
            }
        );
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0