Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
angularjs为详细视图加载不同的模板_Angularjs - Fatal编程技术网

angularjs为详细视图加载不同的模板

angularjs为详细视图加载不同的模板,angularjs,Angularjs,我希望你能帮助我 我想知道如何在angularjs中创建第二组模板。 我有拇指模板-现在我想添加详细视图模板集 目前情况是这样的: 模板在此处加载 我的脚本如下所示: myApp.directive('contentItem', function () { templates = { image: 'image.html', event: 'event.html', article: 'article.html', ad: 'ad.htm

我希望你能帮助我

我想知道如何在angularjs中创建第二组模板。 我有拇指模板-现在我想添加详细视图模板集

目前情况是这样的:

模板在此处加载

我的脚本如下所示:

myApp.directive('contentItem', function () {

    templates = {
      image: 'image.html',
      event: 'event.html',
      article: 'article.html',
      ad: 'ad.html',
      discount: 'discount.html',
      video: 'video.html'

    }

    var linker = function(scope, element, attrs) {
        scope.setUrl = function(){
          return templates[scope.item.content_type];
        }

    }

    return {
        restrict: "E",
        replace: true,
        link: linker,
        scope: {
          item: '=',
          items: '='
        },
        templateUrl: 'main.html'
    };
});
<div ng-include="setURL(item.template_name)"></div>
我想了解详细的意见:

image-detail.html

event-detail.html

article-detail.html

如果我将提交-full.html

如何加载详细视图

这里有一个活生生的例子->


提前谢谢

如果您的
main.html
如下所示:

myApp.directive('contentItem', function () {

    templates = {
      image: 'image.html',
      event: 'event.html',
      article: 'article.html',
      ad: 'ad.html',
      discount: 'discount.html',
      video: 'video.html'

    }

    var linker = function(scope, element, attrs) {
        scope.setUrl = function(){
          return templates[scope.item.content_type];
        }

    }

    return {
        restrict: "E",
        replace: true,
        link: linker,
        scope: {
          item: '=',
          items: '='
        },
        templateUrl: 'main.html'
    };
});
<div ng-include="setURL(item.template_name)"></div>

然后,它将加载在作用域上的
项中指定的模板名称。template_name
,该名称与您的指令一起应为给定给它的
项。您可能需要稍微修改一下
setURL
,以便它返回服务器上的实际完整路径


请记住,
ng include
采用的是表达式而不是名称。这就是为什么在指定硬编码模板文件时,字符串中需要一组额外的单引号。

您不能只执行
?请您再解释一下。我正在尝试为thumb(image.html)加载详细视图(image detail.html)