0

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"
          }
        ];       
    }]);

2 Answers 2

2

You just need to omit the {{}}

<li ng-repeat="grupe in grupes" ng-click="tvarURL(grupe.grupe)">
Sign up to request clarification or add additional context in comments.

Comments

0

Yes you can, but remove the curly brackets.

ng-click="tvarURL(grupe.grupe)"

6 Comments

but function outputs undefiend and i dont know why ng reapeat works just fine
@NatalijaMozuraitene are you trying to pass in the individual grupe? Just do tvarURL(grupe), not grupe.grupe.
If that doesn't work, give us more details in your original post. What does grupe look like? What is tvarURL?
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?
It needs to be on the $scope in your controller, with the name tvarURL. So, $scope.tvarURL = function (value) {... Stuff here...}
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.