从cshtml文件中调用href链接中的angularjs范围函数

时间:2016-11-17 17:27:36

标签: javascript angularjs asp.net-mvc asp.net-mvc-4 razor

这是cshtml内容:

@model MBOS.DTO.ViewModel.Others.ReportTemplateViewModel<MBOS.DTO.ViewModel.BranchBOCAAnalysis>

@if (Model.IncludeTableHeader)
{<thead>
    <tr class="no-borders">

        <th>No.</th>
        <th>Branch</th>
        <th>Assessor</th>
        <th>Rating</th>

    </tr>
</thead>
}

@foreach (var row in Model.Models)
{
    <tr>
        <td>@row.Id</td>
        <td>@row.Branch</td>
        <td>@row.Assessor</td>
        <td><a href="javascript:angular.element(document.getElementById('branchAnalysisCtrl')).scope().RatingDetail();">@row.Rating.FormatDouble() </a></td>
    </tr>
}

这是AngularJs控制器:

(function () {
'use strict';
angular.module("app.branchAnalysis", ["app.base.report"])
    .controller('branchAnalysisCtrl', ['$scope', '$http',
        'appStore', '$controller', '$routeParams', 'Restangular', 'toaster',
        '$location', '$q', '$filter',
  function ($scope, $http, appStore, $controller, $routeParams, Restangular, toaster, $location, $q, $filter) {
 $scope.RatingDetail = function () {
          debugger;
          restangular.one("dashboard/" + (type === 'b' ? 'boca' : 'aoca') + "/assessment/rating/" + assessment.BranchId + "/" + assessment.AssessmentMonth).get().then(function (response) {
              if (type === 'b')
                  $scope.bocaStatusPieViewModel.RatingItems = response.plain();
              else
                  $scope.aocaStatusPieViewModel.RatingItems = response.plain();
          });
      }
   }]);
  })();

我试图从上面的cshtml中提到的href链接调用RatingDetail()函数。 我试过ng-click但也没用。我需要一些好的和有效的例子。我在等待确切的解决方案。

1 个答案:

答案 0 :(得分:0)

你提到你试图让它与ng-click一起使用,但它不起作用,你有什么问题?

使用ng-click http://jsfiddle.net/Lvc0u55v/12116/

查看原始JSFiddle示例