0

New in AngularJs. Finding it complex a little. I have created two text box and a button. Now I want, first I will write something inside the first text box. Then I will click on the button. After that the value of the first text box will get displayed inside the second text box. I have written very little code, I didn't even mentioned the button click function as I am confused on that. Please help me to go further.

<script src="../../Scripts/angular.min.js" type="text/javascript"></script>
</head>
<body>
    <div ng-app="">
        <input type="text" ng-model="type">
        <br />
        <br />
        <input type="button" value="button" onclick="myFunction()" />
        <br />
        <br />
        <input type="text" ng-model="display" />
    </div>
</body>

2 Answers 2

3

in your controller do ,

$scope.myFunction = function () {
    $scope.display = $scope.type;
}

in your html you have to change onclick to ng-click,

<input type="button" value="button" ng-click="myFunction()" />

see this plunk for example, http://plnkr.co/edit/c5Ho1jlixwZFx7pLFm9D?p=preview

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

3 Comments

Can you please explain because I am not understanding that in controller where should I place the code..
i have attached the plunk, see it to understand
I am working in mvc, and in webapplication, in both of then ng-click, ng-app this all are showing error. Why? What thing i need to add to remove the errors from the "ng" tag
0

Check whether you have included angular js file in your HTML.

//add below snippet in your HTML head tag

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">     </script>

4 Comments

//add below snippet in your HTML head tag <script src="ajax.googleapis.com/ajax/libs/angularjs/1.3.14/…>
if not..donwload angular js file and save it locally and add the local path in your HTML head tag
I have downloaded angular.min.js file and added it in my project.

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.