简体   繁体   English

$ location.path未绑定Angular js中的数据

[英]$location.path not binding the data in angular js

I have two angular js controllers. 我有两个angular js控制器。 When the click the ng-href link in recorddetails.html, I am able to see the result binded as "The activity name is Exercise" but the same if I do with ng-click by clicking button with find() in send.html. 当单击recorddetails.html中的ng-href链接时,我能够看到绑定为“活动名称为Exercise”的结果,但是如果通过单击send.html中带有find()的ng-click进行操作,则结果相同。 I am able to see the recorddetails.html but the page is displaying without the data being binded as "The activity name is {{activity}}".I have provided the code belowe for reference.Kindly, provide some valuable solutions. 我可以看到recorddetails.html,但是显示的页面没有数据绑定为“活动名称为{{activity}}”。我提供了以下代码供参考。请提供一些有价值的解决方案。

index.html index.html

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

recorddetails.html recorddetails.html

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

send.html send.html

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

JS file 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");
                        }
}

 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM