我正在尝试在AngularJS中创建一个指令,将我的HTML拆分为可重用的部分:
应用程序/资产/ Javascript角/产品/指令/ products.js:
app.directive('productsfilter', function() {
return {
restrict: 'E',
templateUrl: "/templates/filter-template.html"
}
});
但是,找不到模板:
Error: [$compile:tpload] Failed to load template: /templates/filter-template.html http://errors.angularjs.org/1.2.20/$compile/tpload?p0=%2Ftemplates%2Ffilter-template.html
我也尝试了../templates/filter-template.html
和templates/filter-template.html
,但都没有效果。是因为Rails的资产管道吗?
这是app / assets / javascripts中的文件夹树:
└── products
├── controllers
│ ├── mens_controller.js
│ ├── productscontroller.js
│ ├── womens_eyeglasses_controller.js
│ └── womens_sunglasses_controller.js
├── directives
│ └── products.js
├── filters
│ └── productsfilters.js
├── services
│ └── productsservices.js
└── templates
└── filter-template.html
答案 0 :(得分:0)
我遇到过同样的问题。我的模板路径是:
assets/templates/partials/question/multipleChoice.html
我将模板移动到:
assets/templates/multipleChoice.html嵌入式:
<%= asset_path('multipleChoice.html') %>有效。也许,
asset_path()方法的局限性在于深入挖掘。
为了使方法能够找到模板,我指出了,像这样:
templateUrl: "<%= asset_path('partials/question/multipleChoiceSingleAnswer.html') %>"它起作用了。 (当然,您必须将扩展名更改为.js.erb)。
我不想将模板放在公共文件夹中。我希望Rails为我处理它并让它变得动态。
答案 1 :(得分:0)
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctx);
alertDialogBuilder.setTitle("Title");
alertDialogBuilder
.setMessage("Message")
.setCancelable(false)
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id)
{
//Do something
}
})
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//Do something
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
如果您不使用此宝石,请使用此宝石。
app.directive('productsfilter', function() {
return {
restrict: 'E',
templateUrl: "filter-template.html"
}
});
为我工作。