這只是關於Angular指令的一般問題。爲什麼角度選擇具有返回對象的函數,而不是直接將對象列爲第二個參數?Angular指令的第二個參數,它爲什麼是一個函數?
換句話說,它爲什麼是這樣的:
app.directive('helloWorld', function() {
return {
restrict: 'AE',
replace: 'true',
template: '<h3>Hello World!!</h3>'
};
});
,而不是這樣的:
app.directive('helloWorld',{
restrict: 'AE',
replace: 'true',
template: '<h3>Hello World!!</h3>'
});