Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – 如何从一个角度模块传递另一个模块的值?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Iam New To Angular Concept Iam试图将值从一个模块传递到另一个模块.
我使用Meanjs Generator根据需要为每个模块添加了更多模块.

例:
餐厅模块的餐厅控制器: –

angular.module('restaurants').controller('RestaurantController',['$scope','$http','$stateParams','$LOCATIOn','Authentication','$rootScope'
    function($scope,$http,$stateParams,$LOCATIOn,Authentication,$rootScopE) { 

        $scope.create = function() {
            // Create new Restaurant object

           var resObj = {
                displayName: this.displayName,var restaurant = new Restaurants(resObj);

            // Redirect after save
            restaurant.$save(function(responsE) {
                $LOCATIOn.path('restaurants/'+ restaurant._id);
             **Need to Pass restaurant._id to the Menusconttoller**
            },function(errorResponsE) {
                $scope.error = errorResponse.data.message;
            });
        }; 

]);

我需要将餐馆ID传递给菜单控制器,这可能吗?

angular.module('menus').controller('MenusController1','Authentication'
     function($scope,Authentication) {


       // Create new Menu
        $scope.create = function () {
            $scope.isCreateloading=true;
            var menusObj= {
                'displayName' : this.displayName
                restaurantId  : this.restaurantId // **where i need to recieve the Id which is pased from Restaurant Controller**            
          };


    here i need to get the Id from Restaurant Module 
            $scope.menuForm=menusObj;
                var  menu = new Menus1(menusObj);

                // Redirect after save
                menu.$save(function (responsE) {
                    $LOCATIOn.path('menus/'+menu._id);

                },function (errorResponsE) {
                    $scope.error = errorResponse.data.message;
                });
        };

]);

做了$rootscope BroadcasTing,$scope.emit等,但是所有的例子都在同一个模块中有更多的控制器.哪个不适合我的场景.

请建议: –

**如何将id从一个模块传递到另一个模块?**
谢谢你帮助新手!!

解决方法

你可以这样做:

//this is one module
var myUtilModule = angular.module("myUtilModule",[]);

// this is value to be shared among modules,it can be any value
myUtilModule.value  ("myValue","12345");

//this is another module
var myOtherModule = angular.module("myOtherModule",['myUtilModule']);

myOtherModule.controller("MyController",function($scope,myvalue) {
      // myValue of first module is available here
}

这是教程AngularJS Modularization & Dependency Injection

快乐帮助!

大佬总结

以上是大佬教程为你收集整理的angularjs – 如何从一个角度模块传递另一个模块的值?全部内容,希望文章能够帮你解决angularjs – 如何从一个角度模块传递另一个模块的值?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。