I have the momentModule directive loaded using the .run method in app.js.
I want to inject the factory directive into a form on the rootScope, not
scope.comment. I don't have any controllers in this app. Only the .run
method and the 4 directives. TIA
---factory directive-------
angular
.module('momentModule', [])
.factory('moment', function ($window) {
return $window.moment;
});
----my form-----
angular.module('commentForm', ['$window.moment' ??????? ])
.directive('commentForm', function () {
return {
template: '<form class="commentForm" name="form">' +
'<input type="text" placeholder="Your name"
ng-model="comment.author" name="author"/>' +
'<input type="text" placeholder="Say something..."
ng-model="comment.msg" name="msg"/>' +
'<input type="hidden" ng-model="comment.dateCreated"
name="date" value="{{comment.dateCreated}}"/>' +
'{{comment.dateCreated }}'+
// '<input type="hidden" ng-model="comment.dateCreated" name="date"
value="{{this.window = $window.moment}}"/>' +
'{{comment.dateCreated }}'+
// '<input type="hidden" ng-model="comment.dateCreated" name="date" />' +
'<input type="submit" value="Post"
ng-click="submitComment()"/>' +
'</form>',
restrict: 'E',
link: function postLink(scope, element, attrs) {
scope.comment = {};
scope.submitComment = function(){
var comment = scope.comment;
comment.dateCreated = new Date();
if (!comment.msg || !comment.author) {
return;
}
scope.$emit('submitted', comment);
scope.comment = {};
}
}
};
});
On Sunday, April 24, 2016 at 11:45:04 PM UTC-7, Sander Elias wrote:
>
> Euhm, on second thought.
> Are you sure you load both momentJS itself, and your moment.js module
> file?
>
> Regards
> Sander
>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.