2014-12-22 24 views
0

У меня есть два угловых контроллера js. Когда щелкнуть ссылку ng-href в файле recorddetails.html, Я могу видеть, что результат привязан как «Имя активности - Упражнение», но то же самое, если я делаю это с помощью ng-click, нажав кнопку с функцией find() в send. HTML. Я могу видеть файл recorddetails.html, но страница отображается без привязки данных, так как «Имя действия - {{activity}}». Я предоставил код ниже для ссылки. В конце концов, предоставьте несколько ценных решений.

index.html

  <div ng-controller="controllerOne"> 
      <a ng-href="#/recorddetails/100">Running</a> 
      </div> 

recorddetails.html

 <div ng-controller="controllerTwo"> 
      <p> The activity name is {{activity}}</a>// The scope name is Exercise 
      </div> 

send.html

  <div ng-controller="controllerThree"> 
      <button ng-click="find()"> 
      </div> 

JS файл

  angular.module('exampleapp', ['ngRoute').config(
       [ '$provide', '$httpProvider', '$routeProvider', function($provide,    $httpProvider, $routeProvider) { 
        $routeProvider. 

         when('/recorddetails/:id', { 
          templateUrl: '/records/recorddetails.html', 
          controller: 'controllerTwo' 
          .otherwise({ 
         redirectTo: '/defaultpage' 
         }); 




      app.controller('controllerOne', 
       [ '$scope','$location',function($scope,$location) {`enter code here` 
         } 

      app.controller('controllerTwo', 
       [ '$scope','$location',function($scope,$location) { 
     $scope.activity = "Exercise"; 
         } 

    app.controller('controllerThree', 
       [ '$scope','$location',function($scope,$location) { 
$scope.find = function(){ 
     $location.path("/recorddetails/100"); 
         } 
} 
+0

попробовать $ location.path ("#/recorddetails/100") – dhavalcengg

+0

пытался что приятель его Перенаправление defaultpage.html – Karthik

+0

вы определяете контроллер как на уровень ngroute и уровень шаблона. Если вы укажете свой контроллер для URL-адреса на уровне конфигурации, вам не нужно писать имя contoller в файле шаблона html. – dhavalcengg

ответ

0

var app=angular.module('binding',['ngRoute']) 
 
app.config(['$routeProvider',function ($routeProvider) 
 
{ 
 
    $routeProvider 
 
     .when('/', 
 
     { 
 
      templateUrl:'one.html', 
 
      controller:'controllerOne' 
 
     }) 
 
     .when('/recorddetails/:id', { 
 
      templateUrl: 'recorddetails.html', 
 
      controller: 'controllerTwo' 
 

 
     }) 
 
     .when('/send', { 
 
      templateUrl: 'send.html', 
 
      controller: 'controllerThree' 
 

 
     }) 
 
}]) 
 

 

 

 

 

 

 
app.controller('controllerOne',function($scope,$location){ 
 

 
}) 
 

 
app.controller('controllerTwo', function($scope,$location) { 
 
      
 
     $scope.activity = "Exercise"; 
 
         }) 
 

 

 
    app.controller('controllerThree',function($scope,$location) { 
 
$scope.find = function(){ 
 
    console.log('in 3'); 
 
     $location.path("/recorddetails/100"); 
 
         } 
 
})
<html ng-app="binding"> 
 

 
<head> 
 
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular-route.min.js"></script> 
 
<script src="routefile.js"></script> 
 
</head> 
 

 
<body> 
 

 
<div ng-view> 
 

 
</div> 
 

 
</body> 
 
</html>

Смежные вопросы