beingalex beingalex - 1 year ago 95
AngularJS Question

Set value of input depending on element clicked in Angular

I have made the following plunker:

I would like the value of the input to be the

Here is the code:

<body ng-app="myApp">

<div ng-controller="MyController">
<ul ng-repeat="item in collection">
<li ng-click="edit('{{}}')">{{}}</li>

<input name="myinput" ng-model="myinput" />



var app = angular.module('myApp', [])

.controller('MyController', function($scope, $http) {

$scope.collection = [

$scope.edit = function(current_name) {

this.myinput = current_name;




Answer Source

So there are a few problems here. The first is how you're passing into the edit function. Instead of edit('{{}}') it should simply be edit(

The next is this.myinput in the script.js isn't going to work; it needs to be $scope.myinput.

Finally, the input in the markup needs to be inside the div that defines the controller.

I've modified the Plunkr to work:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download