Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.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
Html angularjs-类指令组件_Html_Angularjs_Angularjs Directive_Angularjs Components - Fatal编程技术网

Html angularjs-类指令组件

Html angularjs-类指令组件,html,angularjs,angularjs-directive,angularjs-components,Html,Angularjs,Angularjs Directive,Angularjs Components,下面是一个示例,其中我展示了将ng repeat item实现为指令或组件之间的区别 我在新闻列表上重复了一次 <div ng-repeat="story in $ctrl.news" class="col-sm-4 col-md-3"> ... </div> 选项1:将故事拇指作为指令执行: app.directive('storyThumb', function(){ return { restrict : 'E', scope : {

下面是一个示例,其中我展示了将ng repeat item实现为指令或组件之间的区别

我在新闻列表上重复了一次

<div ng-repeat="story in $ctrl.news" class="col-sm-4 col-md-3">
    ...
</div>

选项1:将故事拇指作为指令执行:

app.directive('storyThumb', function(){
  return {
    restrict : 'E',
    scope : {
      story : '='
    },
    templateUrl : 'components/news/story/storythumb.html'
  }
});
app.component('storyThumb', {
  bindings : {
    story : '<'
  },
  templateUrl : 'components/news/story/storythumb.html'
});
在故事视图中,我们可以使用以下内容:

<h3>{{story.title}}</h3>
<h3>{{$ctrl.story.title}}</h3>
{{story.title}
选项2:将故事拇指作为组件实现:

app.directive('storyThumb', function(){
  return {
    restrict : 'E',
    scope : {
      story : '='
    },
    templateUrl : 'components/news/story/storythumb.html'
  }
});
app.component('storyThumb', {
  bindings : {
    story : '<'
  },
  templateUrl : 'components/news/story/storythumb.html'
});
app.component('storyThumb'{
绑定:{
故事:'