2016-11-28 88 views
0

我一直停留在这一段上,这是我生成html:ngClick不工作div元素

<div style="margin: 0 5px; border: 2px solid #FFFFFF; height:24px;"> 
    <div id="activity-bar" class="padding0 margin0 ng-isolate-scope" style="width: 100%; background: rgb(179, 179, 179); position: relative; overflow: visible; height: 20px;" ng-style="thisStyle" display-sections="student.history_list" height="20" loading="loading" type="2" user-id="student.fic_student_id"> 
    <div ng-click="console.info('working');" class="activity-section absolute-pos inline-block act-29464 task-background-3 ng-scope" style="left:0%; width:10%;height:20px;" tooltip-placement="top" tooltip-append-to-body="true" uib-tooltip="PrimaryGames: Free Games and Videos 
primarygames.com (click on the bar to view) 
start time: 09:40am"></div> 
    <div ng-click="console.info('working');" class="activity-section absolute-pos inline-block act-54094 task-background-4 ng-scope" style="left:10%; width:10%;height:20px;" tooltip-placement="top" tooltip-append-to-body="true" uib-tooltip="writing0.sumdog.com 
writing0.sumdog.com (click on the bar to view) 
start time: 09:45am"></div> 
    <div ng-click="console.info('working');" class="activity-section absolute-pos inline-block act-54094 task-background-4 ng-scope" style="left:20%; width:10.01%;height:20px;" tooltip-placement="top" tooltip-append-to-body="true" uib-tooltip="writing0.sumdog.com 
writing0.sumdog.com (click on the bar to view) 
start time: 09:50am"></div> 
    <!-- Some more divs --> 
    </div> 
</div> 

的工具提示工作,但NG-点击都没有了,我失去了什么?

+0

任何误差在控制台? –

+0

@SyamPillai nope,none –

+1

'ng-click'不执行任意JavaScript,它执行'$ scope'对象的属性的函数。在这个HTML段的控制器中是否有'$ scope.console.info()'? – Claies

回答

1

在有角的,推荐的方法是调用函数

<div ng-click="consoleinfo('working')" 

在控制器:

$scope.consoleinfo = function(message){ 
console.log(message); 
} 

DEMO

+0

我试着在范围内放置一个函数,并从那里第一次调用它,但那不起作用 –

+0

@NaguibIhab什么都不起作用? – Sajeetharan

+0

ng-click =“myFunction()”不起作用,这就是为什么我试图在表达式中直接添加表达式而不是调用函数,但这种方式并不适用。 –