I started in Angular recently, so I have some questions.
My problem:
I created a directive that I will use in many 'pages' with different controllers in each situation, for example.
Now I can set the controller dynamically well, this problem is solved!
But, in each directive instance, I want to define what is the variable to be changed in the controller, like the ng-model
. If I put directly inside the tag in template it works, but I need it dynamically.
DIRECTIVE:
app.directive('mySelectPicker', function () {
var ddo = {};
ddo.restrict = 'E';
ddo.templateUrl = 'js/directives/views/my-select-picker.html';
ddo.scope = {};
ddo.controller = "@";
ddo.name = "controllerName";
return ddo;
});
MY-SELECT-PICKER.HTML:
OBS1: (ng-repeat is working perfectly with values in the times controllers' array)
OBS2: If I put the ng-model
in the select tag, it works, but will be static!
<select>
<option value="{{time.value}}" ng-repeat="time in times" >{{time.text}}</option>
</select>
CONTROLLER:
app.controller('MyController', function($scope, moment){
$scope.times = []; //array with the options
$scope.val1 = '';
$scope.val2 = '';
});
USING THE DIRECTIVE:
<my-select-picker controller-name="MyController" **ng-model="val1"**></my-select-picker>
<my-select-picker controller-name="MyController" **ng-model="val2"**></my-select-picker>
In resume, I need to define the ng-model
in each <my-select-picker>
to define what is the variable in the controller. How it is possible?