Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple controller not working in angularjs

Tags:

angularjs

jsp

i am new to angular js. i write the code for perform multiple controller concept but it is not working .i dont know where i am doing wrong?

following code i am using

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html >
<html>
<head>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body ng-app="myApp">

<div ng-controller="myCtrl">
<input type="number" ng-model="q">
<input type="number" ng-model="c">
<p>{{ q*c }}</p>
</div>

<div ng-controller="newone">
<p>{{lastName|uppercase}}</p>

</div>




</body>


<script>
var app=angular.module('myApp',[]);
app.controller('myCtrl',function($scope)
{
    $scope.q=10;
    $scope.c=5;

    });
</script>
<script src="control.js"></script>
</html>



**control.js**

var app=angular.module('myApp',[]);
app.controller('newone',function($scope){
    alert();
    $scope.firstName="Vinoth";
    $scope.lastName="Kumar";
    $scope.full=function()
    {
        return $scope.firstName+''+$scope.lastName;
    }

});

above code is not working can any one help me to fix this

like image 583
KVK Avatar asked Nov 15 '25 23:11

KVK


1 Answers

In controller.js you don't need to declare the module again :)

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

change it to var app=angular.module('myApp');

like image 57
squiroid Avatar answered Nov 18 '25 19:11

squiroid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!