angular-input-masks
angular-input-masks copied to clipboard
angular-input-masks-standalone doesnt work with requirejs
Added angular-input-masks-standalone in requirejs config.
gives the following error on load: angular-input-masks-standalone.js:3969 Uncaught TypeError: StringMask is not a constructor
angular: 1.3.13 angular-input-masks: 2.0.0
same here 2.2.0
angular-input-masks-standalone.js:4468 Uncaught TypeError: StringMask is not a constructor
StringMaks is an empty object
this works:
require.config({
paths: {
'angular': 'js/libs/angular/angular.min',
'moment': 'js/libs/moment/moment.min',
'string-mask': 'js/libs/string-mask/string-mask',
'br-validations': 'js/libs/br-validations/br-validations',
'angular-input-masks': 'js/libs/angular-input-masks/angular-input-masks',
},
shim: {
'angular-input-masks': ['angular', 'string-mask', 'moment', 'br-validations'],
'angular': {exports: 'angular'}
},
baseUrl: '/static'
});
require(['modules/app'], function(app) {
app.init();
});
But we actually need to do this imports in a different way inside the npm module. Seems like requireJS is not doing his job there
as a final note: don't use angular-input-masks on a requirejs based application.
There is a workaround that did the trick for me, i imagine it could help someone...
/** Workaround to make angular-input-mask work with requirejs */
var _require = require;
require.config({
waitSeconds: 15,
baseUrl: "",
paths: {
'angular-input-masks': 'assets/libs/angular-input-masks/angular-input-masks',
'string-mask': 'assets/libs/string-mask/string-mask',
'br-validations': 'assets/libs/br-validations/br-validations',
'moment': 'assets/libs/moment/moment'
},
shim: {
"angular": {
exports: "angular"
},
'angular-input-masks': {
deps: ['angular', 'string-mask', 'moment', 'br-validations'],
init: function () {
require = _require;
}
}
},
deps: ['app']
});
The two main points beeing: • Instantiate a new require variable and create the init function inside 'angular-input-masks' shim, like shown above. • You should import the angular-input-masks.js and NOT the standalone version.
On the latest version this workaround does not work anymore.