2016-03-30 27 views
0

AngularJS'de yeni. Ben ng-include kullanmaya çalışıyorum ama başvurulan html dosyalarını göstermiyor.my ng-include çalışmıyor

app.js

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

    app.controller('mainCtrl', [$scope, function($scope) 
    { 
     $scope.templateID = 'testing1.html'; 

     $scope.changeTemplateID = function($scope){ 
      $scope.templateID = 'testing2.html'; 
     } 

    }]); 

index.html dosyasını kod

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

    <head> 
    <script data-require="[email protected]" data-semver="1.5.0" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.js"></script> 
    <link href="style.css" rel="stylesheet" /> 
    <script src="script.js"></script> 
    </head> 

    <body ng-controller="mainCtrl"> 
    <ng-include src="templateID"></ng-include> 
    <h1>Hello Plunker!</h1> 

    <p ng-click="changeTemplateID()">next</p> 
    </body> 

</html> 

kök dizininde iki html dosyası vardır. Bunlar testing1.html ve testing2.html olarak adlandırılır. Hatta doğrudan ng-include içinde "'test1.html'" gibi yönlendirmeye çalıştım.

fakat başarı yok. Herhangi bir yardım? sizin JS kodu

cevap

2

İki hataları: inceleme için

var app = angular.module('myApp', []); 
    //       vvvvvvvv must be a string 
    app.controller('mainCtrl', ['$scope', function($scope) 
    { 
     $scope.templateID = 'testing1.html'; 

     // you don't need to pass $scope here: 
     $scope.changeTemplateID = function(){ 
      $scope.templateID = 'testing2.html'; 
     } 

    }]); 

Plunker.

+0

Hiçbir başarı hala :( – forethought

+0

Ben kodu güncellendi. Sen changeTemplateID parametre olarak $ kapsama sahip, ip gibi ['$scope' olmalıdır. Don' t gerekir ... $ kapsam zaten, er, kapsamı vardır.Kapatıldıysanız plunkr kontrol edin. – Wainage

+0

Lütfen bu https://plnkr.co/edit/HKd1XCZzBXjcaUkSEvzt?p=preview kontrol edin – forethought

0

app.controller('mainCtrl', [$scope, function($scope)... Sizin [$scope değiştirmek ve iyi olacak)

+0

Değiştirildi \t Hala başarı yok :( – forethought

+0

Çalışmalı mı, tarayıcı konsolunda herhangi bir hata var mı? – lomboboo