ng-click不会调用mdDialog中的函数

时间:2016-03-29 23:56:15

标签: angularjs angular-material angularjs-ng-click mddialog

我对AngularJS有点新,但我无法弄清楚为什么ng-click这里不会调用addSt()函数,我想知道它是否与从mdDialog调用它的事实有关。谢谢你的帮助。

继承我mdDialog的html:

var app  = angular.module('epr')
app.controller('adminMainCtr',[ '$scope','$mdDialog',function($scope, $mdDialog) {

  $scope.issues = [
    { name: 'Blizzard', img: 'img/100-0.jpeg', WardMessage: true, index:0, subtasks:[{content:"Shovel Sister Pensioner's Driveway "},
    {content:"Clear downed trees at the Bush's home "}]},
{ name: 'Tornado', img: 'img/100-1.jpeg', WardMessage: false, index:1, subtasks:[{content:"",index:0}] },
{ name: 'Peterson Family Car Crash', img: 'img/100-2.jpeg', WardMessage: false, index:2, subtasks:[{content:"",index:0}] },
{ name: 'Flood', img: 'img/100-2.jpeg', WardMessage: false, index:3, subtasks:[{content:"",index:0}] },
{ name: 'School Shooting', img: 'img/100-2.jpeg', WardMessage: false, index:4, subtasks:[{content:"",index:0}] }
  ];
  $scope.goToIssue = function(issue, event) {
 var parentEl = angular.element(document.body);
$mdDialog.show({
  //parent: parentEl,
  templateUrl:'views/issue.html',
  locals: {
    items: $scope.items,
    issue: issue
  },
  controller: DialogController
});
 function DialogController($scope, $mdDialog) {
   $scope.subtasks = issue.subtasks;
   $scope.addingTask = false;
   $scope.task={content:""};
   $scope.closeDialog = function() {
     console.log($scope.addingTask);
     $mdDialog.hide();
   }
   $scope.removeSubTask = function(subtask,index){
        $scope.subtasks.splice(index,1);
      }
   }
   $scope.addSubTask = function() {
      console.log("here");
   }
   $scope.addingSt = function() {
     if($scope.addingTask === false) {
       console.log($scope.addingTask);
       $scope.addingTask = true;
       return;
     }
     if($scope.addingTask === true) {
       $scope.addingTask = false;
       return;
     }
   }
  }
}]);

这是上面mdDialog的父控制器,(mdDialog的控制器嵌套在其中,适用于所有函数接受addSt()函数)

{{1}}

任何可以借给我的帮助都会非常感激!!!

1 个答案:

答案 0 :(得分:0)

你搞砸了HTML和angylar代码。 发现错误:

1)角度模块初始化。

 var app = angular.module('MyApp', ['ngMaterial'])

2)您在DialogController

之外放置了一些功能

3) md-list-item HTML没有结束标记。

在这里创建了Plunkr。 https://plnkr.co/edit/Sl1WzLMCd8sW34Agj6g0?p=preview。希望它能解决你的问题。

(function() {
  'use strict';

   var app = angular.module('MyApp', ['ngMaterial'])
  app.controller('adminMainCtr', ['$scope', '$mdDialog', function($scope,    $mdDialog) {

$scope.issues = [{
  name: 'Blizzard',
  img: 'img/100-0.jpeg',
  WardMessage: true,
  index: 0,
  subtasks: [{
    content: "Shovel Sister Pensioner's Driveway "
  }, {
    content: "Clear downed trees at the Bush's home "
  }]
}, {
  name: 'Tornado',
  img: 'img/100-1.jpeg',
  WardMessage: false,
  index: 1,
  subtasks: [{
    content: "",
    index: 0
  }]
}, {
  name: 'Peterson Family Car Crash',
  img: 'img/100-2.jpeg',
  WardMessage: false,
  index: 2,
  subtasks: [{
    content: "",
    index: 0
  }]
}, {
  name: 'Flood',
  img: 'img/100-2.jpeg',
  WardMessage: false,
  index: 3,
  subtasks: [{
    content: "",
    index: 0
  }]
}, {
  name: 'School Shooting',
  img: 'img/100-2.jpeg',
  WardMessage: false,
  index: 4,
  subtasks: [{
    content: "",
    index: 0
  }]
}];
$scope.goToIssue = function(issue, event) {
  var parentEl = angular.element(document.body);
  $mdDialog.show({
    templateUrl: 'mddialog.html',
    locals: {
      message: {
        items: $scope.items,
        issue: issue
      }
    },
    controller: DialogController
  });
}

function DialogController($scope, $mdDialog, message) {
  console.log(message)
    //$scope.subtasks = message.issue.subtasks;
  $scope.addingTask = false;
  $scope.task = {
    content: ""
  };
  $scope.closeDialog = function() {
    console.log($scope.addingTask);
    $mdDialog.hide();
  }
  $scope.removeSubTask = function(subtask, index) {
    $scope.subtasks.splice(index, 1);
  }
  $scope.addSubTask = function() {
    console.log("here");
  }
  $scope.addingSt = function() {
    if ($scope.addingTask === false) {
      console.log($scope.addingTask);
      $scope.addingTask = true;
      return;
    }
    if ($scope.addingTask === true) {
      $scope.addingTask = false;
      return;
    }
  }
}

  }]);
})();