单击按钮时,单击angularJS不会显示任何内容

时间:2016-02-24 15:11:29

标签: angularjs

angular js code:

      appModule.controller('dcrlistingCtrl', ['$scope','$modal','$state','$rootScope','loginService', 'servicePOST', 'appConstants','sessionService', '$http', 
      function($scope,$modal,$state,$rootScope,loginService, servicePOST, appConstants,sessionService, $http) {   

        $scope.doctors = function() {
            alert("Doctors");
        };

        $scope.pharmacists = function() {
            alert("pharmacists");
        };

        $scope.stockists = function() {
           alert("pharmacists");
        };

      alert("trial");

      $scope.contact="Doctors";


            $scope.doctors=
    [
      {"patch":"BARIJPUR", "doctor":["RAMA SENA", "SMRITI IRANI","JAGDISH NAIR"]}, 
      {"patch":"Anna", "doctor":["ASHISH NAIK", "SMRITI IRANI", "SAIRAJ NAIK"]}, 
      {"patch":"Peter","doctor":["RATAN PANDEY", "RAMAN SHIVOLKAR"]}
    ];




      }])

html代码:

       <button  type="button" class="btn btn-primary "  ng-click=="doctors()"><b>Doctor</b></button>
       <button type="button" class="btn btn-primary " ng-click=="pharmacists()" ><b>Pharmacist</b></button>
    <button type="button" class="btn btn-primary " ng-click=="stockists()" ><b>Stockist</b></button>

这里有什么棱角分明吗?需要帮助!

警报(&#34;试验&#34;);显示!

但是当我点击这些按钮时,没有显示警告! 为什么会这样? 任何帮助,建议或改变都表示赞赏!

2 个答案:

答案 0 :(得分:1)

每次点击后摆脱双等号。

以下内容:

ng-click=="stockists()"

应该是

ng-click="stockists()"

答案 1 :(得分:0)

  

警告(&#34;试验&#34;)正在显示,因为它不在范围内   您的任何点击功能,而不是控制器的范围   一旦你进入视图,就会调用警报(&#34; trial&#34;)   那特定的控制器。而且,你点击的事实   函数不起作用是因为你有2个等于(==)in   ng-click

<button  type="button" class="btn btn-primary "  ng-click="doctors()"><b>Doctor</b></button>
<button type="button" class="btn btn-primary " ng-click="pharmacists()" ><b>Pharmacist</b></button>
<button type="button" class="btn btn-primary " ng-click="stockists()" ><b>Stockist</b></button>