I have a little problem in using an AngularJS directive with a object property inside an MVC project. The overall structure is a .cshtml page that contains a reference to the scripts file that contains definitions for the app, controller and directives. Everything works fine and the access to all objects and variables is perfectly fine with no errors show on the console.
This is my setup, first of all the directive:
var app = angular.module("dataContainer", ['ngMaterial']);
app.directive('dateTime', function () {
return {
template: '<input type="text" id="datetimepicker" class="form-control">',
restrict: 'E',
require: 'ngModel',
scope: {},
link: function (scope, element, attr) {
$('#datetimepicker').datetimepicker({
format: 'DD/MM/YYYY'
});
}
};
});
First of all I've tried to bind this value inside a $scope
variable, without success, here is the portion of the controller:
app.controller("InvoiceDetailController", function ($scope, $http) {
$scope.dateValue = "";
...
After that I've inserted the html tag like this:
<date-time ng-model="dateValue"></date-time>
But when I trigger an action on a ng-click
to save information the $scope.dateValue
is always an empty string, like it is not able to correctly bind to the div. I also have tried removing scope property from the directive, change it to true
and false
, but nothing works. It is an accessibility problem (maybe related to the datepicker)? Is there a better way to bind variables to directives in AngularJS? Thank you all for the help!