問題描述
Angular 材質日期選擇器在不注入依賴項的情況下工作 (Angular material datepicker working without injecting dependencies)
請在下面找到包含 datepicker 代碼的 codepen,其中添加了少量腳本(moment.js,material.js),但依賴項未註入應用程序。
http://codepen.io/anon/pen/vNLyGJ
我檢查了代碼導出,在其中我可以看到模塊不是創建而是調用。
如果不注入 index.js 中的依賴項,這是如何工作的。
angular.module('MyApp')
.controller('AppCtrl', function($scope) {
$scope.myDate = new Date();
.config(function($mdDateLocaleProvider) {
$mdDateLocaleProvider.formatDate = function(date) {
return moment(date).format('YYYY‑MM‑DD');
};
});
參考解法
方法 1:
Actually the references are there, Click and you could see the references in the Javascript
tab,
UPDATE:
'ngMaterial' is being loaded as a dependency on another file at the end on that codepen:
https://s3‑us‑west‑2.amazonaws.com/s.cdpn.io/t‑114/assets‑cache.js
var demoExampleAppName = 'MyApp';
angular.module(demoExampleAppName, ['ngMaterial', 'ngMessages'])
.run(function($templateCache) {
angular.forEach(assetMap, function(value, key) {
$templateCache.put(key, value);
});
});
MyApp Module is already defined in this case.
(by Raphael、Sajeetharan)