AngularJS - How to render a partial with variables?

前端 未结 3 895
误落风尘
误落风尘 2020-12-08 11:14

For example, I have a partial in car-list.html, and I want to render it in several places with different collections of cars. Maybe something like this:

<
3条回答
  •  广开言路
    2020-12-08 11:51

    You can achieve that easily with a directive.

    Something like that:

    angular.module('myModule')
    .directive('cars', function () {
      return {
        restrict: 'E',
        scope: { 'cars': '=data' },
        template: "
    \n" + " {{car.year}} {{car.make}} {{car.model}}\n" + "
    " }; });

    Then you can use it like that:

    All New Cars

    All Toyotas

    You can find more info about directives here.

提交回复
热议问题