angularjs-eclipse icon indicating copy to clipboard operation
angularjs-eclipse copied to clipboard

Incorrect scope in Angular

Open sudeep30m opened this issue 8 years ago • 0 comments

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

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

First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>

<div  ng-controller="myCtrl2">

This is 2nd Controller
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>

</div>

Full Name: {{firstName + " " + lastName}}

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.firstName= "John";
    $scope.lastName= "Doe";
});
app.controller('myCtrl2', function($scope) {
    $scope.firstName= "John";
    $scope.lastName= "Doe";
});

</script>

</body>
</html>

In this code on asking the definition of firstName in {{firstName + " " + lastName}} the plugin highlights code in MyCtrl2 instead of MyCtrl. In the AngularDefinitionQuery the scope was - "scope":{"controllers":["myCtrl2"],"props":{"lastName":"lastName","firstName":"firstName"},"module":"myApp". Instead of myCtrl2 controller the controller should be MyCtrl.

sudeep30m avatar Jul 06 '17 17:07 sudeep30m