html - Using ng-click in ng-repeat with $index -


i'm trying use ng-click on div ng-repeat element using $index shown below :

html:

<div class="elementcontainer" ng-repeat="element in elements" ng-click="elementurl($index)">     <h2>{{ element.name }}</h2>     <p><strong>{{ element.description }}</strong></p> </div> 

js file:

var app = angular.module('portfolioapp', []);  app.controller('maincontroller', ['$scope', function($scope) {     $scope.elements = [                         {                             "name": "1",                             "description": "abcd"                         },                         {                             "name":"2",                             "description": "lmno"                         },                         {                             "name": "3",                             "description": "xyz"                         }                     ]      $scope.elementurl = function(index) {         if (index == 0) {             $window.location.href = 'first path';         }         else if (index == 3) {             $window.location.href = 'second path';         }         };      }]); 

when click div (.elementcontainer), webpage not redirected given path (local path).
where did wrong?

thanks in advance.

for using $window in controller should inject it

app.controller('maincontroller', ['$scope', '$window', function($scope,$window) { 

or way: use window, note: without $ sign, instead of $window


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

mysql - FireDac error 314 - but DLLs are in program directory -