I am new to angularjs and still learning its intricacies. Currently, I am facing an issue where I can't seem to find a simple solution. I hope someone can assist me with this.
Here is the folder structure that I have created:
Select
->SelectModule.js
->SelectDirective.js
->SelectController.js
->SelectTemplate.html
In each file, here are the contents:
SelectModule.js
angular.module('Select', []);
SelectDirective.js
'use strict';
angular.module('Select').directive('Select', Select);
function Select() {
return {
transclude: false,
scope: {
},
controller: 'SelectController',
templateUrl: 'app/directives/Select/SelectTemplate.html'
};
};
SelectController.js
'use strict'
var SelectMod = angular.module('Select', []);
SelectMod.controller('SelectController', function ($scope) {
console.log($scope.details.data);
});
SelectTemplate.html
<section ng-controller="SelectController">
<div><label>Data:</label><div><input type="number" ng-model="details.data" ng-init="details.data=0.2" step="0.1" /></div></div>
</section>
In the template, I have initialized details.data=0.2. However, when I try to access this initialized data in the controller, there is an error stating "Cannot read property 'data' of undefined." Can anyone help me figure out how to retrieve this value in the controller? I am stuck at this point and any suggestions or advice would be greatly appreciated.