点击里面的,重复,不行

ng-click inside ng-repeat not working

本文关键字:重复 不行      更新时间:2023-09-26

我使用routeProvider路由到"views/userspace.html",它使用"UserspaceController"

"views/userspace.html"识别出这个控制器并发出一个$http请求。这个请求工作文件,我可以看到值在"views/userspace.html"(内部ng-repeat)。然而,在同一个控制器中,我定义了$scope.videoClick函数,它似乎不起作用。知道为什么吗?

   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

  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

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

修改函数以接受参数

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

或者修改HTML

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

这是因为在你的;

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

您有一个不需要的逗号,这会使函数抛出错误,因为它期望另一个属性。

如果你在HTML中使用变量,你应该使用Sajeetharan的答案