Question: This question is inspired by:

> 
> [ng-model in numeric input does not affect scope](https://stackoverflow.com/questions/33830869/ng-model-in-numeric-input-does-not-affect-scope/33831167#33831167)
> 
> 
> 

In that question I was surprised to learn that somehow I have nested controllers even though I have exactly one controller per template and I have no custom directives. This might have something to do with Ionic.

I had a problem that I couldn't access primitive $`scope` properties without wrapping them in objects. I had this problem regardless what I named the primitive property. I could only access it from my template if I wrapped it in an object or referred to $parent.

How come I can't access the primitives regardless of name? I would understand that there can be a naming conflict, but no name worked. And if no name works, then why do primitives wrapped in objects work? Why do I not need to write `$parent.object` in my template to access an object attached to my `$scope`?

Answer: 
**Accessing vs Defining values**

When accessing a value (such as using **{{ value }}**, or **method()**), the application will climb up parent scopes looking for the value until it reaches $rootScope: the first version found, if any, is then used.

When defining a value, however (such as using **value = 'foo'**), it applies it to the current scope, even if a value exists with the same key under a parent scope.

**Defining primitives vs defining object properties**

When setting a primitive value such as 'value', you're simply defining what value is:

```
value = 123;

```

But when defining the property of an object, the object has to be accessed before the property change can be applied to it:

```
object.value = 123;

```

The above code looks for object, and applies the change to its value property. If object doesn't exist in the current scope, the application will search up the parent scopes to find object, so it can access it. Then, the change to value is applied to that instance of object. If object doesn't exist at all, the code will throw an error because it is essentially the below:

```
null.value = 123;

```

**Example**

Similar functionality can be seen in vanilla Javascript through prototypal inheritance.

```
var parent = { primitive: 123, object: { value: 123 } };
var child = Object.create(parent);

console.log(child.primitive); // 123, from parent
console.log(child.object.value); // 123, from parent

child.primitive = 456; // modifies own primitive key
console.log(child.primitive); // 456, from self
console.log(parent.primitive); // still 123

child.object.value = 456; // modifies parent's object's value
console.log(child.object.value); // 456, from parent
console.log(parent.object.value); // 456, since it was modified above

```
> 
> JavaScript objects are dynamic "bags" of properties (referred to as
>  own properties). JavaScript objects have a link to a prototype object.
>  When trying to access a property of an object, the property will not
>  only be sought on the object but on the prototype of the object, the
>  prototype of the prototype, and so on until either a property with a
>  matching name is found or the end of the prototype chain is reached.
> 
> 
> 

**[Read more here](https://developer.mozilla.org/en/docs/Web/JavaScript/Inheritance_and_the_prototype_chain)**

You need to know the prototype inheritance of javascript first.

Then understand how scope works with this very helpful **[guide](https://github.com/angular/angular.js/wiki/Understanding-Scopes)**.