简体   繁体   English

ng-click内ng-repeat不起作用

[英]ng-click inside ng-repeat not working

I am using routeProvider to route to "views/userspace.html" which uses "UserspaceController" 我正在使用routeProvider路由到使用“ UserspaceController”的“ views / userspace.html”

The "views/userspace.html" recognizes this controller and makes request a $http request. “ views / userspace.html”识别此控制器并将请求设为$ http请求。 This request works file and i can see values in "views/userspace.html" (inside ng-repeat). 该请求有效的文件,我可以在“ views / userspace.html”(ng-repeat内部)中看到值。 However, in the same controller i have defined $scope.videoClick function which does not seems to work. 但是,在同一个控制器中,我定义了$scope.videoClick函数,该函数似乎不起作用。 Any idea why? 知道为什么吗?

   var application = angular.module("tss.application", 
    [
        "ngRoute",
        "ui.bootstrap"
    ]);

    application.config(function($routeProvider) 
    {
      $routeProvider
          .when("/", {
            templateUrl : "views/main.html",
            controller: "LoginController"
          })
          .when("/files", {
            templateUrl : "views/userspace.html",
            controller: "UserspaceController"
          });
    });

userspace_controller.js userspace_controller.js

  angular.module('tss.application').controller("UserspaceController",  
    function($scope, $log, $http, $uibModal)
    {       
        $http(
            {
                url     : "/dirlist",
                method  : "GET",
            }).then(function successCallback(response) 
            {
                $scope.lists = response.data;
            }, 
            function errorCallback(response) 
            {
                window.alert("Dir list could not be get");
            });     
        $scope.videoClick = function()
        {           
            $log.info('received.');
            $uibModal.open(
            {
                templateUrl: '/views/content.html',

            });
        };          
    });

userspace.html userspace.html

   <li ng-repeat="list in lists" ng-click="videoClick(list.src)">{{list.name}}</li>

Change your function to accept a parameter 更改函数以接受参数

$scope.videoClick = function(val) {
    $log.info('received.');
    $uibModal.open({
        templateUrl: '/views/content.html',

    });
};

Or change the function in HTML 或更改HTML中的功能

<li ng-repeat="list in lists" ng-click="videoClick()">{{list.name}}</li>

It's because in your; 那是因为你

$scope.videoClick = function()
    {           
        $log.info('received.');
        $uibModal.open(
        {
            templateUrl: '/views/content.html',

        });
    }; 

You have a comma which isn't needed, which makes the function throw an error because it's expecting another property. 您有一个不需要的逗号,这会使该函数引发错误,因为它需要另一个属性。

Also if you're using the variable you pass through your HTML, you should use Sajeetharan's answer. 另外,如果您使用的是通过HTML传递的变量,则应使用Sajeetharan的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM