Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Can i use angular expression in function to pass certain value?

Question can i use regular javascript function or i must use only functions that i specified in My OptionControler?

my HTML HEAD
<script>
  function tvarURL(value){console.log(value)}
</script>

my HTML

<div ng-controller="OptionControler" >
<ul>
<li ng-repeat="grupe in grupes" ng-click="tvarURL(grupe.grupe)">
            {{grupe.grupe}}
    </li>
</ul>
</div>

My OptionControler with JSON FILE This is smaler version of json file

    var module = angular.module('app', ['onsen']);
    module.controller('OptionControler', ['$scope',
        function rodyti($scope) {



    $scope.grupes = [
    {
        "grupe": "MM4-1",
        "URL": "https://spreadsheets.google.com/feeds/list/1BYBxGHSPEGNrV2jvJV_c6gJwRzkHwy0OL4avnk8O9S0/od6/public/values?alt=json",
        "fakultetas": "TKF",
        "tipas": "nuolatines",
        "kursas": "kursas1"
          },
    {
        "grupe": "MM4-2",
        "URL": "https://spreadsheets.google.com/feeds/list/1FQmHYUpIt6GYxOKB63Smtk-6LBUiKUyCY_HTniGuR_M/od6/public/values?alt=json",
        "fakultetas": "TKF",
        "tipas": "Nuolatinės",
        "kursas": "kursas1"
          }
        ];       
    }]);
share|improve this question

2 Answers 2

up vote 0 down vote accepted

Yes you can, but remove the curly brackets.

ng-click="tvarURL(grupe.grupe)"
share|improve this answer
    
but function outputs undefiend and i dont know why ng reapeat works just fine –  Natalija Mozuraitene Dec 21 '14 at 19:26
    
@NatalijaMozuraitene are you trying to pass in the individual grupe? Just do tvarURL(grupe), not grupe.grupe. –  Jacob Turner Dec 21 '14 at 19:34
    
If that doesn't work, give us more details in your original post. What does grupe look like? What is tvarURL? –  Jacob Turner Dec 21 '14 at 19:41
    
ng-reapeat outputs grupe.grupe just fine and i have long list of names i want to click on individual name and output that name in console. Question where my function tvarURL must be? In controler or can i define it like regular javascript function? –  Natalija Mozuraitene Dec 21 '14 at 19:42
    
It needs to be on the $scope in your controller, with the name tvarURL. So, $scope.tvarURL = function (value) {... Stuff here...} –  Jacob Turner Dec 21 '14 at 19:45

You just need to omit the {{}}

<li ng-repeat="grupe in grupes" ng-click="tvarURL(grupe.grupe)">
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.