【问题标题】:Using Blaze Template in Angular Meteor在 Angular Meteor 中使用 Blaze 模板
【发布时间】:2016-03-24 07:44:52
【问题描述】:

我正在尝试在 Angular Meteor 应用程序中使用 useraccounts:bootstrap,方法是使用 urigo:angular-blaze-template 包来使用 useraccounts:bootstrap 提供的 blaze 模板 {{> atForm}}

问题:我在网页上遇到错误:meteorTemplate: There is no template with the name 'todoList'。有什么想法吗?

useraccounts.html

<template name="todoList">
    {{> atForm}}
</template>

<blaze-template name="todoList"></blaze-template>

routes.js

angular.module('myApp').config(function($urlRouterProvider, $stateProvider, $locationProvider) {
    $locationProvider.html5Mode(true)

    $stateProvider
        .state('useraccounts', {
            url: '/useraccounts',
            templateUrl: 'client/useraccounts/views/useraccounts.html',
        })

    $urlRouterProvider.otherwise('/foo')
})

按照 Jos Jarink 的建议,丢失模板错误消失了!但是{{&gt; atForm }}不包含任何内容,只有下面的代码嵌套在uiViewdiv里面。

blaze-html-templates 包已被删除,添加这个回来似乎没有任何区别。

<div class="container">
    <!-- uiView:  -->
    <div ui-view="" class="ng-scope">
        <blaze-template name="atForm" class="ng-scope">
            <div class="at-form ng-scope">
            </div>
        </blaze-template>
    </div>
</div>

更新

Github 回购: https://github.com/nyxynyx/useraccounts-angular

.meteor/packages 中取消注释blaze-html-templates 会出现错误

Errors prevented startup: While determining active plugins: 
error: conflict: two packages included in the app (angular-templates and templating) are both trying to handle *.html 

【问题讨论】:

标签: javascript angularjs meteor angular-meteor


【解决方案1】:

将 Blaze 模板放在另一个文件中,就像放置 Angular html 的位置一样。也就是说,将&lt;template&gt; 放在另一个文件中,&lt;blaze-template&gt; 保留在您的 Angular html 文件中。

useraccounts.html

<blaze-template name="todoList"></blaze-template>

useraccounts_blaze.html

<template name="todoList">
    {{> atForm}}
</template>

另请参阅:https://stackoverflow.com/a/34073593/5543045

更新并检查 atForm 是否存在:

如果您想检查 blaze-template 是否找到了 atForm 或任何其他模板,您可以添加一个简单的模板助手来尝试查找模板名称。 比如:

Template.todoList.helpers({
    isThatTemplateHere: function (name) {
        var tmpl = Template[name];
        if (tmpl)
            return name + ' was found';
        else
            return name + ' was not found';
    }
});

在你的模板中:

<template name="todoList">
    {{isThatTemplateHere "atForm"}}
    {{> atForm}}
</template>

【讨论】:

  • 谢谢,缺少模板错误现在消失了,但页面上没有呈现来自atForm 模板的任何内容。有任何想法吗?更新了问题并提供了更多详细信息。
  • 我添加了 useraccounts:bootstrap 包并使用 atForm 复制/粘贴了您的 html,它按预期呈现。它显示一个登录框。在您的情况下,blaze-template 似乎找不到 atForm 模板。如果找不到模板,blaze-template 不会通知我们一些警告或错误,它只是不呈现任何内容,这就是您所遇到的。
  • 我用一些代码更新了我的答案,以检查是否可以找到 atForm。这可能有助于调查 atForm 未呈现的问题。将您的线路 &lt;blaze-template name="atForm" class="ng-scope"&gt; 更改为 &lt;blaze-template name="todoList" class="ng-scope"&gt;
  • 我尝试使用干净的流星项目使用atForm 并最终遇到了同样的问题。也许我误解了什么,让我创建一个 github repo 来重现问题
  • 刚刚添加了一个我用来回答关于混合 Angular 和 Blaze 的类似问题的 repo(问题是包 juliancwirko:s-alert 包中还有一个名为 sAlert 的模板)。 github.com/MGA1600/angular-blaze.git
猜你喜欢
  • 2016-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-09
  • 1970-01-01
  • 2016-02-27
相关资源
最近更新 更多