【问题标题】:Unexpected end of expression:nextEvent [duplicate]表达式意外结束:nextEvent [重复]
【发布时间】:2018-11-16 16:43:59
【问题描述】:

这不是插值问题。我删除了代码中的所有插值,但仍然出现相同的错误。

当单击指向在 app.js 中定义为 .state 的页面引用的 ng-click 时,我收到此错误。这个错误是什么意思?我无法通过谷歌搜索找到任何对它的引用,特别是nextEvent

   // app.js
  .state('tab.clubs', {
      cache: false,
      url: '/clubs',
      views: {
        'tab-clubs': {
          templateUrl: 'templates/tab-clubs.html',
          controller: 'ClubCtrl'
        }
      }
    })
    .state('tab.club-detail', {
      url: '/clubs/:clubID',
      views: {
        'tab-clubs': {
          templateUrl: 'templates/detail-clubs.html',
          controller: 'ClubDetailCtrl'
        }
      }
    })

还有我模板中的调用。注意,有一个 ng-repeat 嵌套在另一个 ng-repeat 中 - 但是我认为这不会导致问题,因为所有内容都使用预期的 ID 和索引正确呈现......并且只有在我单击时才会生成错误嵌套的 ng-repeat 中的 <div ng-click="....">

  <div id="club_tabItem_{{club.data[0].clID}}" style="padding:5px;border-bottom:1px solid grey;" class="item-remove-animate item-avatar" ng-repeat="club in clubs">
    <div id="loc_{{club.data[0].clID}}" style="left:15px;">
      <div ng-click="showEvents(club.data[0].clID);">
        <h3>{{club.data[0].clVendor}}
          <!-- <span style="margin-left:15px;">Location: {{club.data[0].clAddress1}}, {{club.data[0].clCity}}</span> -->
          <i style="font-size:25px;float:right;" class="icon ion-android-arrow-dropdown-circle icon-accessory customColor1"></i>
        </h3> 
        <span style="padding-left:30px;">{{club.data[0].clDesc}}</span>
      </div>
      <div id="eventsDiv_{{club.data[0].clID}}" style="width:100%;display:none;margin-top:10px;background-color:lightGrey;">
        <div id="events_{{event.ceID}}" style="width:80%;margin-left:20%;display:inline-block;" ng-repeat="event in club.events">
          <div ng-click="$location.url('/tab/clubs/' + event.ceID)" >
             <div style="float:left;font-size:14px;font-weight:bolder;">{{event.ceName}} ({{event.ceName1}}) </div>
             <div style="float:left;margin-left:15px;">Location: {{club.data[0].clAddress1}}, {{club.data[0].clCity}}</div> 
             <div style="float:left;margin-left:15px;">Next: {{nextEvent(event)}}</div>
              <i style="font-size:25px;" class="icon ion-android-arrow-dropright-circle icon-accessory customColor1"></i>
          </div>
        </div>
      </div>
    </div>
  </div>

在上述情况下,调用是:ng-click="$location.url('/tab/clubs/1')" - 在控制器中我有 $scope.$location = $location 和 $location 被正确传递到控制器。

据我所知,调试甚至无法到达 .state detail-clubs 页面的控制器。该错误在进入控制器之前触发。

关于错误的更多信息:

ionic.bundle.js:20306 Error: [$parse:ueoe] Unexpected end of expression: nextEvent(club.event[club.eIndex]
http://errors.angularjs.org/1.3.13/$parse/ueoe?p0=nextEvent(club.event%5Bclub.eIndex%5D
    at ionic.bundle.js:8762
    at Parser.consume (ionic.bundle.js:20747)
    at Parser.functionCall (ionic.bundle.js:21022)
    at Parser.primary (ionic.bundle.js:20694)
    at Parser.unary (ionic.bundle.js:20970)
    at Parser.multiplicative (ionic.bundle.js:20953)
    at Parser.additive (ionic.bundle.js:20944)
    at Parser.relational (ionic.bundle.js:20935)
    at Parser.equality (ionic.bundle.js:20926)
    at Parser.logicalAND (ionic.bundle.js:20917)
(anonymous) @ ionic.bundle.js:20306
(anonymous) @ ionic.bundle.js:17256
$broadcast @ ionic.bundle.js:23421
(anonymous) @ ionic.bundle.js:40889
processQueue @ ionic.bundle.js:21888
(anonymous) @ ionic.bundle.js:21904
$eval @ ionic.bundle.js:23100
$digest @ ionic.bundle.js:22916
$apply @ ionic.bundle.js:23205
(anonymous) @ ionic.bundle.js:20063
eventHandler @ ionic.bundle.js:11713
triggerMouseEvent @ ionic.bundle.js:2863
tapClick @ ionic.bundle.js:2852
tapTouchEnd @ ionic.bundle.js:2975

【问题讨论】:

  • 请包含错误消息的完整文本和堆栈跟踪。
  • @georgeawg - 添加了完整的错误消息
  • ng-click 表达式看起来很粗略。它将 AngularJS 表达式与插值混合在一起。
  • 分而治之。当你有少量代码,但问题的根源完全不清楚时,开始一点一点地删除代码,直到问题消失- 然后添加最后一部分。另见AngularJS Error Reference - $PARSE UEOE
  • 也许这里的骗子确实是错误的,但我投票支持 保持关闭 因为缺少 MCVE。我没有看到任何阻止您将其缩减为重现错误的最小示例的东西,但是您还没有这样做;取而代之的是,此示例设法立即不完整(我们无法复制和粘贴并运行它,因为模板依赖于$scope 变量,例如club)并且比必要的时间长得多。 (我敢打赌,您不需要一半的 HTML 来重现错误;您当然不需要将行从代码块一侧推开的所有类和内联样式。)跨度>

标签: javascript angularjs cordova angular-ui-router ionic-v1


【解决方案1】:

不要混合使用 AngularJS 表达式和插值:

<div id="events_{{event.ceID}}" style="width:80%;margin-left:20%;display:inline-block;" ng-repeat="event in club.events">
    ̶<̶d̶i̶v̶ ̶n̶g̶-̶c̶l̶i̶c̶k̶=̶"̶$̶l̶o̶c̶a̶t̶i̶o̶n̶.̶u̶r̶l̶(̶'̶/̶t̶a̶b̶/̶c̶l̶u̶b̶s̶/̶{̶{̶e̶v̶e̶n̶t̶.̶c̶e̶I̶D̶}̶}̶'̶)̶"̶>̶
    <div ng-click="$location.url('/tab/clubs/'+event.ceID)">
       <div style="float:left;font-size:14px;font-weight:bolder;">{{event.ceName}} ({{event.ceName1}}) </div>
       <div style="float:left;margin-left:15px;">Location: {{club.data[0].clAddress1}}, {{club.data[0].clCity}}</div> 
       <div style="float:left;margin-left:15px;">Next: {{nextEvent(event)}}</div>
        <i style="font-size:25px;" class="icon ion-android-arrow-dropright-circle icon-accessory customColor1"></i>
    </div>
</div>

有关详细信息,请参阅Why mixing interpolation and expressions is bad practice

【讨论】:

  • 感谢您的阅读。我更改了代码以反映您的编辑,但我仍然遇到同样的错误。现在我正在寻找一个开放式表达式...我在代码中越来越远地查看它可能来自哪里,但没有找到任何东西。
  • 问题与插值或 ng-repeat 无关(据我所知)...我在嵌套的 ng-repeat 内调用函数{{ nextEvent(event) }},错误是单击链接时被抛出该函数。目前仍然不确定为什么......但我一直专注于 ng-repeat 和链接本身。
  • 实际上...nextEvent 是 angluarjs 的事情。我更改了函数的名称,单击链接时仍然调用相同的错误。在这一点上我完全糊涂了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-06
  • 2023-03-20
  • 2018-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多