Angular: Scope example

A simple treeview implemented with angular and ngInclude

by Richard Houltz

HTML

<div ng-controller="ParentController">
    <span>Parent scope:</span><br/>
    
    <input type="text" ng-model="intValue"/><span>Simple value</span><br/>
    <input type="text" ng-model="anObject.intValue"/><span>Object property</span><br/>
    
    <div ng-controller="ChildController">
        <span>Child scope:</span><br/>
        <input type="text" ng-model="intValue"/><span>Simple value</span><br/>
        <input type="text" ng-model="anObject.intValue"/><span>Object property</span><br/>

        <!-- 
        <span>Child scope:</span><br/>        
        <input type="text" ng-model="$parent.intValue"/><span>Object property</span><br/>
        !-->

    </div>    
</div>

JavaScript

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

    .controller("ParentController", ['$scope', function ($scope) {
    $scope.intProperty = 1;
    $scope.anObject = {
        intProperty: 1
    };
}])

    .controller("ChildController", ['$scope', function ($scope) {
}]);