Как передать данные в HTML-шаблон AngularJs

0

У меня есть HTML-шаблон AngularJs, шаблон отображается, однако ни один из тегов <td> не заполняется. Мне интересно, как передать свой компонент JSON Object в шаблон.

<div>
    <h4>Alert</h4>
    <table class="table">
        <tr>
            <th>Type</th>
            <td>{{component.type}}</td>
        </tr>
        <tr>
            <th>Alert</th>
            <td>{{component.alert}}</td>
        </tr>
    </table>
</div>

Я хочу передать данные в этот шаблон, но у меня возникают проблемы с этим.

data: $scope.component вызывает проблему.

$scope.components = 
    [
    {type: "Mobilizer",  alert:"mobilizer2 went down", status: "Down"},
    {type: "Dispacther", alert:"message rate is, status: "Problem"},
    {type: "Listener",   alert:"No Alert", status: "Up"},
    {type: "OutBound Charge", alert:"No Alert", status: "Up"}
];  

   $scope.openDialog = function(component) {
            ngDialog.open({
                templateUrl: 'handlebars/alert-template.html',
                data: $scope.component
            });
        };
    })

Моя функция AngularJs, которая вызывает функцию:

  <tr ng-repeat="component in components | orderBy:'status'" ng-click="openDialog(component)">
  <td>{{component.type}}</td>
  <td ng-if="component.status == 'Up'" class="alert-success">{{component.status}}</td>
  <td ng-if="component.status == 'Problem'" class="alert-warning">{{component.status}}</td>
  <td ng-if="component.status == 'Down'" class="alert-danger">{{component.status}}</td>
  </tr>
  • 0
    Вы не показываете весь свой HTML, поэтому я собираюсь сделать удар в темноте. Правильно ли вы связали контроллер с помощью атрибута ng-controller?
Теги:
ng-dialog

1 ответ

0
Лучший ответ
 $scope.component = component;
        ngDialog.open({
            template: 'handlebars/alert-template.html',
            scope: $scope

Мне пришлось назначить область действия внутри моей функции.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню