2016-11-07 88 views
0

你好,我有嘗試的角度JS角JS多個指令

var app = angular.module("myApp", []); 

app.controller("myController", function($scope){ }); 

app.directive("myDirective1", function(){ return { 
    template: "<h1> hello this is directive with template </h1>" }; }); 

app.directive("myDirective2", function(){ return{ 
    restict: 'A', 
    templateUrl: /directiveTry.html }; }); 

多個指令,我創造了這個main.html中

<body ng-controller= "myController as myCtrl"> 
    <h1>Hello Plunker!</h1> 
    <my-Directive1></my-Directive1> 
    <my-Directive2></my-Directive2> 
    </body> 

和directiveTry.html只有一個

<h1> hello I am external on file </h1> 

我無法顯示文本,我的mystake在哪裏?

感謝答案

+1

restict:參數不存在。它是「限制」,A代表屬性。您正在尋找E.另外,您應該在引號之間放置templateUrl值。這是一個字符串 –

+0

確定完成,但現在不顯示我的指令2 – nowaySync

+0

的語法應該是'<我的指令性...' –

回答

0
app.directive('myDirective1', function() { 
    return { 
    restrict: 'AE', 
    replace: 'true', 
    template: '<h3>Hello World!!</h3>' 
    }; 
}); 

用作:

<my-directive1></my-directive1> 
<div my-directive1></div> 

讀取任何簡單的文章或觀看YouTube '如何角創建簡單的指令' https://www.sitepoint.com/practical-guide-angularjs-directives/

+0

我有一個模板完成的,現在我需要顯示的消息從外部HTML – nowaySync

+0

要求Google http://techfunda.com/howto/482/custom-directive-with-templateurl –

0

問題解決了

mystake我忘了「r」的限制 :(((((

+0

呀......看看我的意見。 –