0

View 1:

<div ng-controller="ctrl1">
    <button ng-click="goToExtendedForm({'name':'aaa'})">
    </button>
</div>

ctrl1:

    $scope.selectedList = {
        name: ""
    };

    $scope.goToForm = function(e) {
        $scope.selectedList.name = e.name;
        $state.go('view2');
        console.log(e); // prints updated value
    };

View 2:

<div ng-controller="ctrl1">

<input
        id="name"
        name="name"
        type="text"
        ng-model="selectedList.name"
        ng-readonly="true"
/>
</div>

But the input box is always empty, even though to get to the view the goToForm() is called. Why doesn't it update the HTML value? Views are changed with ui.router's $state.

6
  • 1
    put your code in plunkr.com Commented May 15, 2018 at 9:58
  • where goToForm() defined ? Commented May 15, 2018 at 10:00
  • Give the entire code, please see how to ask a question on stack. Commented May 15, 2018 at 10:01
  • without an option to call goToForm(), how you fire goToForm() function ?? Commented May 15, 2018 at 10:09
  • When asking a question about a problem caused by your code, you will get much better answers if you provide code people can use to reproduce the problem. That code should be… Complete – Provide all parts needed to reproduce the problem. See How to create a Minimal, Complete, and Verifiable example. Commented May 15, 2018 at 10:14

3 Answers 3

3

From your description, your code is supposed to work. Check if you are passing the right parameter into the function. Here is a working demo:

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
  $scope.selectedList = {
    name: ""
  };

  $scope.goToForm = function(e) {
    $scope.selectedList.name = e.name;
    console.log(e); // prints updated value
  };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>

<div ng-app="myApp" ng-controller="myCtrl">

  <button ng-click="goToForm({'name':'aaa'})">Change</button>
  <br>
  <input type="text" ng-model="selectedList.name" ng-readonly="true" />

</div>

Sign up to request clarification or add additional context in comments.

Comments

0

Try adding $scope.$apply() at the end of your $scope.goToForm function

Comments

0

Try this ;

HTML Code

  <div ng-app>
      <div ng-controller="ClickToEditCtrl">
        <input
                                id="name"
                                name="name"
                                type="text"
                                ng-model="selectedList.name"
                                ng-readonly="true"
                        />
                        <button ng-click="goToForm(testUserDetails)" >Go To</button>

                        </button>
      </div>
    </div>

Define controller like this;

function ClickToEditCtrl($scope) {
  $scope.selectedList = {
        name: ""
    };
$scope.testUserDetails ={
        name: "nimal"
}
    $scope.goToForm = function(e) {
        $scope.selectedList.name = e.name;
        console.log(e); // prints updated value
    };
}

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.