0

到“视图/ userspace.html”,它采用“UserspaceController”NG单击内部纳克重复我使用routeProvider路由不工作

“视图/ 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> 

回答

2

更改函数接受一个参数

$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> 
+0

nop..still不工作 – Nishant

+0

@Nishant我可以看到你的代码吗? – Sajeetharan

+0

https://1drv.ms/u/s!AntZxg2kwlRrixPHx4Ws7-s7hO6n – Nishant

0

这是因为在你的;

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

     }); 
    }; 

你有一个不需要的逗号,这使得该函数抛出一个错误,因为它期待着另一个属性。

另外,如果您使用的是通过HTML传递的变量,则应该使用Sajeetharan的答案。

+0

没有。它不起作用 – Nishant