あなたは、共通のconfigオブジェクトを使用して、それが必要な場合はカスタムプロパティでそれを拡張することができた:私は元/ベースコントローラと依存性注入を使用することができるだろう、ということでした場合
var getConfig = function() {
return {
controller: function() { console.log('default controller'); },
templateUrl: 'default.html',
bindings: { }
}
}
// default component
app.component('one', getConfig())
// different templateUrl
app.component('two', angular.extend(getConfig(), {
templateUrl: 'another.html'
}))
// different controller
app.component('three', angular.extend(getConfig(), {
controller: function() { console.log('another controller'); }
}))
// ... and even extend controller itself
app.component('four', angular.extend(getConfig(), {
controller: function() {
// inherit default controller
getConfig().controller.call(this)
// and add custom functionality
this.newMethod = function() {}
}
}))
? – Troy
はい、もちろんです。 – dfsq
詳細な例をありがとう。例4では、 'config.controller.call(this)'という行は私に無限の再帰を与えます。私はそれが基本設定(?)で別の名前が必要だと思うが、それは例1と2を壊すだろう... – Troy