2017-02-10 19 views
-1

下面是我使用方法是在范围仍然没有得到来自名为NG单击

<div ng-controller="profileEventsCtrl" > 
<div class="row mainNavbar" data-ng-show="hideVanityPlate"> 
<div id="navigatornavbarview" data-ui-view="navigatornavbarview"></div> 
</div> 
<div class="Profileindex" ng-init="init()"> 
<div id="profile" style="padding-bottom:20px"> 
    <div class="col-md-12"> <h1>My Events</h1></div> 
    <div class="row"> 
     <div class="col-md-2"> 
      <div profile-navigation=""></div> 
     </div><!--col-md-2--> 
     <div class="col-md-10"> 
      <accordion close-others="true"> 
       <accordion-group is-open="status.open" ng-repeat="userEvent in userEvents"> 
        <accordion-heading> 
         {{userEvent.Event.Title}} 
         <div class="condensed medium pull-right date">{{userEvent.Event.FormatedEventDateStartToEnd}} &nbsp</div> 
         <div class="condensed medium lineblock"> 
          <span class="place ">{{userEvent.Event.Location}}</span> | <span class="place" ng-click="switchEvent(userEvent.Event.Code)" ><span>{{SwitchEventText}}</span></span> 
         </div> 
        </accordion-heading> 
       </accordion-group> 
      </accordion> 
     </div> 
    </div> 
</div> 

这里的HTML是,我使用

(function (ng, app) { 
'use strict'; 

app.controller('profileEventsCtrl', ['$scope', '$location', '$state', '$rootScope', '$q', '$timeout', 'localization','profileSvcs', profileEventsCtrl]); 
function profileEventsCtrl($scope, $location, $state, $rootScope, $q, $timeout, localization, profileSvcs) { 
    $scope.userEvents = {}; 
    $scope.SwitchEventText = "Switch Events" 

    $scope.init = function() { 
     $rootScope.currentScope = $scope; 
     $scope.hideVanityPlate = true; 
     $scope.getMyEvents(); 

    }; 


    $scope.getMyEvents = function() { 
     profileSvcs.getMyEvents().then(function (response) { 
      $scope.userEvents = response.data; 
     }); 
    } 

    $scope.switchEvent = function (eventCode) { 
     var newLocationHash = "/" + $rootScope.cultureCode + "/navigator/" + eventCode + "/profile"; 
     $location.path(newLocationHash); 
    } 



}  
})(angular, app); 
控制器

所有其他组件工作正常。数据正在从API加载并被填充。但ng-click不起作用。我不会遇到任何控制台错误,因此难以调试。

此外还要测试功能switchEvent是否在范围内。我试过ng-init而不是ng-click,并且函数被调用了ng-repeat中的每一行,因此我认为switchEvent在范围之内。

+0

是你的重复工作? – Sajeetharan

+0

@Sajeetharan是的,ng-repeat工作正常 – kaysush

回答

0

尝试通过与对象NG点击和访问点击函数内部的财产

ng-click="switchEvent(userEvent)" 

控制器:

$scope.switchEvent = function (eventCode) { 
     var newLocationHash = "/" + $rootScope.cultureCode + "/navigator/" + eventCode.Event.Code + "/profile"; 
     $location.path(newLocationHash); 
    } 
+0

没有效果,仍然没有调用控制台上的函数也没有错误。 – kaysush

+0

我可以通过团队查看器看到您的代码或创建一个plunker – Sajeetharan

+0

http://plnkr.co/edit/63Leeo2M4ArOi45rwg3q – kaysush

0

看到这一行: -

<span class="place "> 
    {{userEvent.Event.Location}} 
</span> | 
<span class="place" ng-click="switchEvent(userEvent.Event.Code)"> 
    <span> 
     {{SwitchEventText}} 
    </span> 
</span> 

根据你在哪里你点击这个方法调用

它可能没有被调用,因为您没有按确切的跨度。可能是...

尝试将其更改为

<span class="place "> 
    {{userEvent.Event.Location}} 
</span> | 
<span class="place" ng-click="switchEvent(userEvent.Event.Code)"> 
    {{SwitchEventText}} 
</span> 

取出里面跨度

+0

看看我创建的plnkr http://plnkr.co/edit/63Leeo2M4ArOi45rwg3q。它接近此代码并具有相同的问题。 – kaysush

相关问题