AngularJS 控制器 'ngSwitch',指令 'ngSwitchWhen' 需要,找不到

AngularJS Controller 'ngSwitch', required by directive 'ngSwitchWhen', can't be found

我有一个主模板来执行一些向导,例如逐步完成一些模板:

<div ng-controller="StepController">
 <div ng-switch="step">
  <div ng-switch-when="1">
           <div ng-controller="ImportController">
              <div ng-include src="'static/javascripts/import/upload.html'">
           </div>
     <button type="button" class="btn btn-success btn-s"  ng-click="setStep(2)"> Next Step</button>
  </div>
  <div ng-switch-when="2">
     <div ng-include src="'static/javascripts/authentication/blank.html'">
      <button type="button" class="btn btn-success btn-s"  ng-click="setStep(3)"> Next Step</button>
  </div>
  <div ng-switch-when="3">
     <div ng-include src="'static/javascripts/authentication/blank.html'">
     <button ng-click="setStep(3)"></button>
  </div>
</div>

然而,当我点击第一个按钮渲染下一个模板时,出现错误

Controller 'ngSwitch', required by directive 'ngSwitchWhen', can't be found

当我点击按钮后查看源代码时,ng-switch div 标签就在那里,所以我不确定为什么它不起作用。

我很确定您遗漏了一些结束元素。我重新格式化了代码。

<div ng-controller="StepController">
    <div ng-switch="step">
        <div ng-switch-when="1">
            <div ng-controller="ImportController">
                <div ng-include src="'static/javascripts/import/upload.html'">
                </div>
                <button type="button" class="btn btn-success btn-s"  ng-click="setStep(2)"> Next Step</button>
            </div>
            <div ng-switch-when="2">
                <div ng-include src="'static/javascripts/authentication/blank.html'">
                    <button type="button" class="btn btn-success btn-s"  ng-click="setStep(3)"> Next Step</button>
                </div>
                <div ng-switch-when="3">
                    <div ng-include src="'static/javascripts/authentication/blank.html'">
                        <button ng-click="setStep(3)"></button>
                    </div>
                </div>

缺少元素

<div ng-controller="StepController">
    <div ng-switch="step">
        <div ng-switch-when="1">
            <div ng-controller="ImportController">
                <div ng-include src="'static/javascripts/import/upload.html'">
                </div>
                <button type="button" class="btn btn-success btn-s"  ng-click="setStep(2)"> Next Step</button>
            </div>
        </div>
        <div ng-switch-when="2">
            <div ng-include src="'static/javascripts/authentication/blank.html'">
                <button type="button" class="btn btn-success btn-s"  ng-click="setStep(3)"> Next Step</button>
            </div>
        </div>
        <div ng-switch-when="3">
            <div ng-include src="'static/javascripts/authentication/blank.html'">
                <button ng-click="setStep(3)"></button>
            </div>
         </div>
     </div>
</div>

问题是在不正确的代码中,第二个和第三个 ng-switch-when 元素不在 ng-switch 元素的正下方。 ng-switch-when 查看它的 ng-switch 语句的父元素,它丢失了。