Skip to content

Incorrect scope in Angular #223

Description

@sudeep30m
<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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions