Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 我无法在段落标记内显示$scope数据_Angularjs - Fatal编程技术网

Angularjs 我无法在段落标记内显示$scope数据

Angularjs 我无法在段落标记内显示$scope数据,angularjs,Angularjs,我的代码哪部分是错的?? 如果它有很多错误,请不要给我不一样的:D我在Angularjs这么新 <script> demoapp = angular.module('demoapp', []); demoapp.factory('simplefactory', function ($scope) { //var customers = [{ name: 'Alireza', family: 'massali' }, { name: 'Ehsan', family: 'abdo

我的代码哪部分是错的?? 如果它有很多错误,请不要给我不一样的:D我在Angularjs这么新

<script>
demoapp = angular.module('demoapp', []);
demoapp.factory('simplefactory', function ($scope) {
    //var customers = [{ name: 'Alireza', family: 'massali' }, { name: 'Ehsan', family: 'abdolahi' }, { name: 'Ali', family: 'Shirvanian'}];
    var customers ="3576324";
    //var factory = {};
    this.GetCust = function () {
       return customers;
    };


    this.PostCust = function (customer) {
        return customers;
    };
    return factory;
});



var xxx = angular.module('mmodule', []);
var conts = {}
conts.simple = function ($scope, simplefactory) {
    $scope.name = simplefactory.GetCust();
}

conts.simple1 = function ($scope) {
    $scope.name1 = "2222";
}

xxx.controller(conts);

demoapp=angular.module('demoapp',[]);
demoapp.factory('simplefactory',函数($scope){
//var客户=[{name:'Alireza',family:'massali'},{name:'Ehsan',family:'abdolahi'},{name:'Ali',family:'Shirvanian'}];
var客户=“3576324”;
//变量工厂={};
this.GetCust=函数(){
返回客户;
};
this.PostCust=功能(客户){
返回客户;
};
返回工厂;
});
var xxx=angular.module('mmodule',[]);
var conts={}
conts.simple=函数($scope,simplefactory){
$scope.name=simplefactory.GetCust();
}
conts.simple1=函数($scope){
$scope.name1=“2222”;
}
xxx.控制器(续);

这是HTML

<div ng-app='mmodule'>
<p ng-controller='simple'>{{name}}</p></div>

{{name}


您的代码不正确。在工厂中,您返回的是未定义的
工厂
。如果要使用
GetCust
和其他函数,则必须返回
this

您的代码不正确。在工厂中,您返回的是未定义的
工厂
。如果您想使用
GetCust
和其他函数,您必须返回
this

,我可以尝试让您从正确的行开始。 您似乎正在使用2个模块,我认为您有理由这样做。 “mmodule”模块正在尝试使用“demoapp”模块中定义的工厂。但它不知道它在哪里。因此,您需要做的第一件事是将“demoapp”模块注入到“mmodule”中。 所以您需要更改行var xxx=angular.module。。。。到

var xxx=angular.module('mmodule', ['demoapp']);
现在,工厂中定义的功能应该可以使用了

你建工厂的方式和我建工厂的方式不同。我将使用:

 demoapp.factory('simplefactory', function () {

   var customers ="3576324";
   //var factory = {};
    return{
     GetCust: function () {
       return customers;
     },


     PostCust: function (customer) {
       return customers;
     }
  };
});

这里有一个问题:

我可以试着让你从正确的线路开始。 您似乎正在使用2个模块,我认为您有理由这样做。 “mmodule”模块正在尝试使用“demoapp”模块中定义的工厂。但它不知道它在哪里。因此,您需要做的第一件事是将“demoapp”模块注入到“mmodule”中。 所以您需要更改行var xxx=angular.module。。。。到

var xxx=angular.module('mmodule', ['demoapp']);
现在,工厂中定义的功能应该可以使用了

你建工厂的方式和我建工厂的方式不同。我将使用:

 demoapp.factory('simplefactory', function () {

   var customers ="3576324";
   //var factory = {};
    return{
     GetCust: function () {
       return customers;
     },


     PostCust: function (customer) {
       return customers;
     }
  };
});

这里有一个plunker:

您需要的是:

demoapp = angular.module('demoapp', []);
demoapp.factory('simplefactory', function () {
工厂不接受范围

    var customers = "3576324";

    return {
        GetCust: function () {
            return customers;
        },


        PostCust: function (customer) {
            return customers;
        }
    }
您需要返回一个包含函数的对象

});



var xxx = angular.module('mmodule', ['demoapp']);
最重要的是,将demoapp模块插入其中

var conts = {}
conts.simple = function ($scope, simplefactory) {
    $scope.name = simplefactory.GetCust();
}

conts.simple1 = function ($scope) {
    $scope.name1 = "2222";
}

xxx.controller(conts);

您需要的是:

demoapp = angular.module('demoapp', []);
demoapp.factory('simplefactory', function () {
工厂不接受范围

    var customers = "3576324";

    return {
        GetCust: function () {
            return customers;
        },


        PostCust: function (customer) {
            return customers;
        }
    }
您需要返回一个包含函数的对象

});



var xxx = angular.module('mmodule', ['demoapp']);
最重要的是,将demoapp模块插入其中

var conts = {}
conts.simple = function ($scope, simplefactory) {
    $scope.name = simplefactory.GetCust();
}

conts.simple1 = function ($scope) {
    $scope.name1 = "2222";
}

xxx.controller(conts);

你想干什么?!控制台中是否有任何错误?您的调用
xxx.controller(conts)
似乎很奇怪,因为您传递了一个散列(或者最近在Angular API中做了一些我遗漏的更改?)。您是否尝试过使用通常的
xxx.controller(“简单”,函数(…){…})
注册控制器?你能把这个放到live编辑器里给我们一个链接吗?你想做什么?!控制台中是否有任何错误?您的调用
xxx.controller(conts)
似乎很奇怪,因为您传递了一个散列(或者最近在Angular API中做了一些我遗漏的更改?)。您是否尝试过使用通常的
xxx.controller(“简单”,函数(…){…})
注册控制器?你能把这个放到live编辑器中并给我们一个链接吗?