2016-03-03 75 views

回答

0

這裏給出的模塊名作爲docsSimpleDirective是plunker 主演關閉您還沒有在NG-應用這就是定義你的名字爲什麼你的應用是不是工作 和腳本文件的順序不同。

http://plnkr.co/edit/2SthQC5fADsi1rdEhq3C?p=preview

var app = angular.module('docsSimpleDirective', []); 

    app.controller('Controller', function($scope) { 
     console.log('Hi'); 
     $scope.customer = { 
      name: 'Naomi', 
      address: '1600 Amphitheatre' 
     }; 
    }) 
    .directive('myCustomer', function() { 
     return { 
      template: 'Name: {{customer.name}} Address: {{customer.address}}' 
     }; 
    }); 

你的HTML

<!DOCTYPE html> 
<html ng-app="docsSimpleDirective"> 

    <head> 
    <link rel="stylesheet" href="style.css"> 

    <script src = "https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script> 
    <script src="script.js"></script> 
    </head> 

    <body> 
    <h1>Hello Plunker!</h1> 

    <div ng-controller="Controller"> 
    <div my-customer/> 
</div> 

    </body> 




</html> 

希望它可以幫助

+0

非常感謝。我希望我能接受這兩個答案。 –

0

請更改angular.module('docsSimpleDirective', ['index.html'])angular.module('docsSimpleDirective', [])index.html不是依賴項。我們正在將js文件鏈接到html文件。而不是相反。

另外,請更改<html ng-app><html ng-app='docsSimpleDirective'>因爲我們已經在angular.module('docsSimpleDirective', [])

+0

做,但仍然沒有工作..... –

+0

請參閱本plunker。 http://plnkr.co/edit/m7XS228hn04MREj5qDg0?p=preview –

+0

所以cdn不工作?沒有機會你有一個1.5的鏈接,因爲我從那裏得到一個,並沒有工作 https://cdnjs.com/libraries/angular.js/1.5.0 感謝您的幫助 –