[英]ng-click inside ng-repeat not working
我正在使用routeProvider路由到使用“ UserspaceController”的“ views / userspace.html”
“ 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的答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.