2016-07-15 3 views
0

У меня проблема при загрузке нескольких шаблонов с помощью директивы Где я передаю некоторое значение области управления и в директиве я проверяю значение и относительно загружаю html.Проблема: Загрузка нескольких шаблонов с помощью директивы

первый HTML:

<a class="col-xs-3" > <div stop-watch template="topic-view" name="oCandidateDetails.name" time-of-interview="oCandidateDetails.doi" class="stop-watch"></div> </a> 

второй HTML:

<div stop-watch template="candidate-view" name="candidateInfo.name" time-of-interview="candidateInfo.dateOfInterview" class="stop-watch"></div> 

директива:

angular.module('iSourcingApp.tpModule') 
.directive('stopWatch', function() {debugger 
    return { 
     restrict: 'A', 
     templateUrl: '<ng-include src="getTemplateUrl()"/>', 
     replace: false, 
     scope: { 
      name: "=", 
      timeOfInterview: "=", 
      template:"=" 
     }, 
     controller: function($scope, $interval) {debugger 
      $scope.getTimeRemaining = function(endtime) { 
       $scope.t[$scope.name].total = Date.parse(endtime) - Date.parse(new Date()); 
       $scope.t[$scope.name].seconds = Math.floor(($scope.t[$scope.name].total/1000) % 60); 
       $scope.t[$scope.name].minutes = Math.floor(($scope.t[$scope.name].total/1000/60) % 60); 
       $scope.t[$scope.name].hours = Math.floor(($scope.t[$scope.name].total/(1000 * 60 * 60)) % 24); 
       $scope.t[$scope.name].days = Math.floor($scope.t[$scope.name].total/(1000 * 60 * 60 * 24)); 
      } 
      $scope.initializeClock = function(endtime) { 
       $scope.t = {}; 
       $scope.t[$scope.name] = {}; 
       $scope.updateClock = function() { 
        $scope.getTimeRemaining(endtime); 
        $scope.t[$scope.name].hours = ('0' + $scope.t[$scope.name].hours).slice(-2); 
        $scope.t[$scope.name].minutes = ('0' + $scope.t[$scope.name].minutes).slice(-2); 
        $scope.t[$scope.name].seconds = ('0' + $scope.t[$scope.name].seconds).slice(-2); 

        if ($scope.t[$scope.name].total <= 0) { 
         clearInterval($scope.timeinterval); 
        } 
       } 
       $scope.updateClock(); 
       $scope.timeinterval = $interval($scope.updateClock, 1000); 
      } 
      $scope.initializeClock($scope.timeOfInterview); 
      //function used on the ng-include to resolve the template 
      $scope.getTemplateUrl = function() {debugger; 
       //basic handling 
       if ($scope.template == 'candidate-view') { 
        return './tpModule/views/stopWatchView.html'; 
       } 
       if ($scope.template == 'topic-view') { 
        return './tpModule/views/topicStopWatchView.html'; 
       } 
      } 
     } 
    }; 
}); 

Проблема здесь я получаю сообщение об ошибке говорящее

angular.js:13708 Error: [$compile:tpload] Failed to load template: <ng-include src="getTemplateUrl()"/> (HTTP status: 404 Not Found) 

Я не понимаю, почему я получаю эту ошибку здесь

любая помощь очень ценится.

ответ

0

Это не templateUrl,

template: '<ng-include src="getTemplateUrl()"/>', 
0

Я думаю, что проблема в свой адрес, чтобы устранить эту ошибку, убедитесь, что URL шаблона написано правильно и решает исправить абсолютный адрес

Просто попробуйте это

'../tpModule/views/stopWatchView.html' 
Смежные вопросы