could someone please explain me the difference between these two piece of code, and the way to manage it.
Here is my index.html
<body ng-app="docsIsolateScopeDirective">
<div ng-controller="Controller">
<my-customer info="naomi" ></my-customer>
{{nameUser}}
<my-customer info="igor"></my-customer>
</div>
</body>
Here is my script.js
(function(angular) {
'use strict';
angular.module('docsIsolateScopeDirective', [])
.controller('Controller', ['$scope', function($scope) {
$scope.nameUser = 'naomi';
$scope.naomi = { name: 'Naomi', address: '1600 Amphitheatre' };
$scope.igor = { name: 'Igor', address: '123 Somewhere' };
}])
.directive('myCustomer', function() {
return {
restrict: 'E',
scope: {
customerInfo: '=info'
},
templateUrl: 'my-customer-iso.html'
};
});
})(window.angular);
And finally my my-customer-iso.html :
Name: {{customerInfo.name}} Address: {{customerInfo.address}}
The result is this :
Name: Naomi Address: 1600 Amphitheatre
naomi Name: Igor Address: 123 Somewhere
Question is : I would like to set the info of my markup with a scope variable (basically $scope.nameUser which contains "naomi"). But when I write
<my-customer info={{nameUser}} </my-customer> // or <my-customer info="{{nameUser}}"> </my-customer>
instead of
<my-customer info= "naomi"></my-customer>
the code is broken and I don't understand why.. Is the scope variable can't be consider like a string ? Thanks
EDIT : Even if I write :
<my-customer info = nameUser> </my-customer>
The result is still different. I don't receive an error but the output is :
Name: Address:
Name: Igor Address: 123 Somewhere
So I think that I'm missing something about the interaction between the controller and the directive. See here : https://plnkr.co/edit/hbi4whoH3Dj9lDV3vVzZ?p=preview