即使条件通过,ng-if也不起作用

时间:2014-09-23 14:36:35

标签: javascript angularjs

在我的以下功能中,我们使用了

"ng-if"[ng-if=\"GoalCard.assignment.totalResponsesToGrade>0**\"]显示/隐藏按钮但即使条件通过也没有显示按钮。

angular.module("goalCard/studentWritingTab.tpl.html", []).run(["$templateCache", function($templateCache) {
  $templateCache.put("goalCard/studentWritingTab.tpl.html",
    "<div class=\"large-12 columns students-table-wrapper student-writing-passage\">\n" +
    "       <div class=\"summary-report-head\">\n" +
    "           {{locale['label.goalCard.title.writing']}}\n" +
    "       </div>\n" +
    "       <div class=\"small-12 columns students-table table-header goal-student-writing-report border-theme reset-foundation\" flexcroll ><div  id=\"goalCardStudentWritingReport\"></div></div>     \n" +
    "       <div class=\"clear\"></div>\n" +
    "       <div class=\"table-header-passage\"><a class=\"button button-one large-text passge-next right\" wga-click=\"label.goalCard.gradePassages\" ng-if=\"GoalCard.assignment.totalResponsesToGrade>0\" ng-click=\"gradePassages()\">{{locale['label.goalCard.button.writing']}}</a></div>\n" +
    "</div> ");
}]);

1 个答案:

答案 0 :(得分:0)

你确定

GoalCard.assignment.totalResponsesToGrade

是否正确实例?

尝试访问它:

ng-if="GoalCard['assignment']['totalResponsesToGrade']>0"

您的范围需要如下所示:

$scope.GoalCard = {};
$scope.GoalCard.assignment. = {};
$scope.GoalCard.assignment.totalResponsesToGrade = 0;