0

How can I set a value of some variable in javascript stored in angularjs controller when some html element is clicked. For example:

    angular.module('app',[])
        .controller('appController', function($scope, $http){
        $scope.onTheMove = null;
}

I want to set onTheMove to some value when ng-click is triggered from html.

<input type="radio" name="player" id="radio-1" ng-click="onTheMove = 1">
1
  • 1
    if you are not using "appController as" before the input tag, what you have looks fine too! Commented May 26, 2017 at 22:08

1 Answer 1

1

First you need to put it in the same controller:

  <div ng-controller="appController">
      <input type="radio" name="player" id="radio-1" ng-click="changeValue()">
    </div>

then create the change function

$scope.changeValue = function() {
    var val = $scope[propName];
    $scope.onTheMove = 1;
  };

or even easiear with ng-model

<div ng-controller="appController">
      <input type="radio" name="player" id="radio-1" ng-click="onTheMove" ng-value ="1">
    </div>
Sign up to request clarification or add additional context in comments.

Comments

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.