0
我嘗試創建我的directiv。當我啓動相同的代碼時,angularjs停止。我自己的指令不起作用AngularJS
demo
https://codepen.io/Turqus/pen/yPPmbG?editors=1011
有人能解釋我什麼是錯的?
我嘗試創建我的directiv。當我啓動相同的代碼時,angularjs停止。我自己的指令不起作用AngularJS
demo
https://codepen.io/Turqus/pen/yPPmbG?editors=1011
有人能解釋我什麼是錯的?
你必須把指令名稱的第一個字母小寫爲控制檯的錯誤告訴你(F12在任何瀏覽器,然後轉到控制檯選項卡):
錯誤日誌:「指令/組件名稱'MyExample'無效,第一個字符必須是小寫字母「
(function(){
angular
.module('App', [])
.controller('ExampleCtrl', ExampleCtrl);
function ExampleCtrl() {
var vm = this;
vm.name = "yo";
};
})();
(function(){
angular
.module('App')
.directive('myExample', MyExample); // <----------------- HER
function MyExample() {
var directive = {
restrict: 'E',
template: '<div>one more time</div>',
controller: 'MyController',
controllerAs: 'vm'
};
return directive;
}
function MyController() {
}
})();