角度指令未显示在ng-Switch中

Angular Directive not showing in ng-Switch

本文关键字:ng-Switch 显示 指令      更新时间:2023-09-26

我有 4 个基于 var.type 显示的模板。我有 2/4 正确显示,但由于某些原因,其中 2 个没有渲染任何东西。在 HTML 中,我看到开关被正确激活,但指令没有按预期放置在其中。

angular.module('lodgicalWebApp');
angular.module('lodgicalWebApp')
  .directive('lodReportVariableCgflookup', function () {
    return {
      template: '{{var.name}}<label for="repeatSelect"> {{var.name}} </label> '
    			<select name="repeatSelect" ng-model="Vars[var.name]" id="repeatSelect" ng-model="data.repeatSelect"> '
      				<option ng-repeat="option in  var.possibleVals" value="{{option.id}}">{{option.name}}</option> '
    			</select>',
      restrict: 'EA'
    };
  });
angular.module('lodgicalWebApp')
  .directive('lodReportVariableBoolean', function () {
    return {
      template: '{{var.name}}<input ng-model="Vars[var.name]" type="checkbox" ng-true="{{var.value}}">',
      restrict: 'EA',
      
    };
  });
angular.module('lodgicalWebApp')
  .controller('ReportsCtrl', function ($scope,  $routeParams, LodgicalReportService,  Report) {
    $scope.selectedReport.variables = [
      {name: "Start Date",possibleVals:[],type: "Date", value: "2016-01-18"},
      {name: "Operator",possibleVals: [{id:1,name:"test"},{id:2,name:"thanksStackOverflow"}], type: "CfgLookup"},
      {name: "Include Security Deposits", type: "Boolean", value: "False"}
    ]
  
  });
			<div ng-repeat="var in selectedReport.variables">
				<div ng-switch="var.type">
                     <!-- CfgLookup not rendering -->
					<div ng-switch-when="CfgLookup" data-lod-report-variable-cfglookup ></div>
					<div ng-switch-when="Boolean" data-lod-report-variable-boolean></div>
					<div ng-switch-when="Date" data-lod-report-variable-date ></div>
					<div ng-switch-when="CfgLookup-Multi" data-lod-report-variable-cfglookup></div>
				</div>
			</div>		

这不是一个有效的例子,但它应该足以说明希望能阐明这一重大挫折。

提前谢谢。

你有一个错别字,肯定会搞砸它:

"

data-lod-report-variable-cfglookup"是你在HTML代码中写的指令名称,而JS代码中的指令名称是"lodReportVariableCgflookup"。(cfglookup vs cgflookup)

编辑:此外,我注意到您在您说不起作用的两个指令上都使用了相同的指令"lodReportVariableCgflookup"。

您可能还有其他问题,但我会从那个:)开始