ngRoute:如何在AngularJS中使用templateUrl和controller?

时间:2017-10-05 16:49:32

标签: javascript angularjs angularjs-ng-route

我开发了一个类似Quiz.com的项目,我在角度js中有一些代码但是如何在角度js中使用模板Url和控制器来动态包含。

示例:国家/地区下拉

<script type="text/ng-template" id="pages/start.html">
  <h2>Which of Your Friends Know You the Most?</h2>
   <center><h3>Select your Country: </h3></center>
   <center>
      <div class="dropdown">
         <select class="dropbtn" ng-init="selectedRegion = region[0]" ng-
 model="selectedRegion" ng-options="x for x in region">
        </select>

      </div>
  </center> 
</script>

Angular Code:

 app.config(function($routeProvider) {
   $routeProvider
  .when('index.html', {
   templateUrl : 'pages/start.html',
   controller  : 'startController'
 })
.otherwise({redirectTo: '/'});

});

app.controller('startController',  ['$scope', '$window', '$location', 
'$timeout', 'dmFactory', function($scope, $window, $location, $timeout, 
 dmFactory) {


  $scope.selectedRegion;
  $scope.region = ["India", "United States", "Other"];


   $scope.user= "nonquestioner";
   if($scope.user == "questioner")
  {
   $window.location.href = 'quiz/vzmfbd.html';
   }

  $scope.startQuiz = function(lang){
   dmFactory.set("language", lang);
   dmFactory.set("region",$scope.selectedRegion);
   console.log("Language is"+ lang);
    $timeout(function() { $scope.highlight = 0;
    $location.path("/initial");
   }, 300);
   };

   }]);

在哪里使用pages / start.html 它的位置。

0 个答案:

没有答案