簡體   English   中英

Angular 1.x組件templateUrl無法在DOM中呈現

[英]Angular 1.x component templateUrl not rendering in DOM

我的組件設置如下:

// app/my-component/my-component.js
app.component('myComponent', {
    bindings: {
        bindingA: '=',
        bindingB: '='
    },
    templateUrl: 'app/my-component/my-component.tpl.html',
    controller: MyComponentCtrl
});

// app/my-component/my-component.tpl.html
<div>
    <input type="text" ng-model="$ctrl.bindingA" />
    <input type="text" ng-model="$ctrl.bindingB" />
</div>

沒有拋出任何錯誤; 我的模板文件在Chrome的開發工具中顯示得很好。 XHR請求的網絡預覽顯示正確,但不會在DOM上呈現...

如果我將templateUrl替換為template ,則字符串在DOM中將顯示得很好。

有任何想法嗎?

在想敲打鍵盤之后,我意識到這段代碼干擾了templateUrl的響應:

$httpProvider.interceptors.push(function() {
    return {
            'response': function (response) {
                response.data = response.data.d;

                return response;
            }
        }
    });

只需更改為: if (response.data.d) response.data = response.data.d;

生活中的另一天,我會告訴你...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM