[英]How can i use the function ng-click in my case?
我有一個div,其圖片每9秒更改一次,我想保留它,但是我想在用戶單擊時更改圖片。 我認為最簡單的方法是使用ng-click函數,但是我不知道我的代碼:在HTLM中:
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 session fondbleuSession">
<div>
<div ng-controller="eventCtrl">
<div ng-repeat="data in event" ng-if="data.id == actualSession">
<div class="sessionTxt">
<h1>{{data.title}} </h1>
<p>{{data.description}} </p>
</div>
<!-- ng-click here ? --> <a ng-href="{{data.url}}" class="sessionImg" ng-style="{'background-image':'url({{data.src}})'}" >
</a>
</div>
</slider>
</div>
</div>
</div>
並且在eventCtrl
app.controller('eventCtrl', function($scope, $interval) {
$scope.actualSession = 0;
var sessionLength = 0;
// INFORMATION GENERAL EVENT
// id = reference de l'image pour l'ordre de passage (+1 a chaque nouveau slide ajouté)
// title = titre de l'event
// description = resume rapide de l'event
// src = adresse de l'image
// url = lien de redirection vers article/sharepoint...
$scope.event = [
{
"id": 1,
"title": "Site Events",
"description": "",
"src": "images/index/event/Photo1.jpg",
"url": ""
},
{
"id": 2,
"title": "Site Events",
"description": "",
"src": "images/index/event/Photo2.jpg",
"url": ""
},
{
"id": 3,
"title": "Site Events",
"description": "",
"src": "images/index/event/Photo3.jpg",
"url": ""
},
{
"id": 4,
"title": "Site Events",
"description": "",
"src": "images/index/event/Photo4.jpg",
"url": ""
},
{
"id": 5,
"title": "Site Events",
"description": "",
"src": "images/index/event/Photo5.jpg",
"url": ""
}
];
sessionLength = _.size($scope.event);
$interval(function() {
$scope.actualSession = $scope.actualSession + 1;
if ($scope.actualSession == sessionLength) {
$scope.actualSession = 0;
}
}, 9000); //timer switch event (1000 = 1 seconde)
})
而且我不知道是否有可能具有這兩個功能:x秒后自動更改圖片,並在用戶單擊時更改圖片。 此外,當我們拍攝最后一張照片時,我不知道該去誰看第一張照片非常感謝,並祝您愉快
嘗試在錨標記周圍包裹div並在其中使用ng-click,希望它應該能工作。
如果您要更改actionSession變量,它應該很簡單:
ng-click="ctrl.someFunc()"
然后在控制器中:
someFunc() {
$scope.actualSession = $scope.actualSession === sessionLength - 1 ? 0 : $scope.actualSession++;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.