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