错误:[$ compile:ctreq]指令所需的控制器,找不到

时间:2016-02-17 20:38:16

标签: javascript angularjs angularjs-directive slim-lang

我一直从需要另一个指令的指令中得到此错误。我不明白的是,此代码可以在其他页面上运行而不会出现问题。这是一些代码:

正在爆炸的指令:

newco.directive 'signupShippingForm', [
  () ->
    {
    templateUrl: '/pages/signup/billing/shipping_form'
    require: ['signupShippingForm', '^addressScrub']
    controllerAs: 'ctrl'
    link: (scope, element, attrs, ctrls) ->
      ctrl = ctrls[0]
      addressScrubCtrl = ctrls[1]
      ctrl.updateAddress = () ->
        addressScrubCtrl.scrubAddress()
    controller: ['$scope', 'productService', 'UsStatesCodes'
      ($scope, productService, UsStatesCodes) ->
        ctrl = @
        $scope.shippingPackages = productService.shippingPackage()
        $scope.states = UsStatesCodes

        $scope.toggleBillingInfo = ()->
          $scope.billingOption.same = !$scope.billingOption.same
          if $scope.billingOption.same
            _.extend $scope.shippingInfo, $scope.billingInfo
          else
            $scope.shippingInfo = {}

        ctrl.showShippingToggle = !$scope.showSimpleForm

        @
    ]
    }
]

我收到的错误是:

Error: [$compile:ctreq] Controller 'addressScrub', required by directive 'signupShippingForm', can't be found!

我的HTML正在爆炸的地方是:

   form(name="updateShippingForm" ng-submit="save(updateShippingForm.$valid, billingInfo, shippingInfo)" autofill-sync)

      billing-form-prefill
        address-scrub
          .container
            signup-billing-form(ng-if="true == false")
            signup-simple-billing-form(ng-if="true == false")

            hr

          signup-shipping-form ng-if="true == true"

        signup-billing-package(ng-if="true == false")

        signup-billing-agreement

所以address-scrub是signupShipping表单的父级,所以我认为^语法会找到它。 ng-ifs是因为我从另一种形式复制HTMl,这个设置当前正在工作,所以我添加了那些禁用这些元素。

页面的控制器只是:

@newco.controller 'UpdateShippingController', ($location, $routeParams, $scope, userService, BillingInfo) ->

1 个答案:

答案 0 :(得分:1)

您是否尝试过要求'^^addressScrub'