我最近开始使用AngularJS,现在我正在构建我的应用程序的方式是这样的:
var app = angular.module('app', ['SomeController', 'MainController']);
app.controller('MainController', function ($scope) {
// do some stuff
}
Run Code Online (Sandbox Code Playgroud)
var SomeController= angular.module('SomeController', []);
SomeController.controller('SomeController', function ($scope) {
$scope.variable = "test";
// do some otherstuff
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是模块之间没有共享范围.从MainController我不能得到变量"test"例如.
$scope在它们之间共享,或者可以将所有内容放在一个控制器中?如果我有3个类,可以说:Mainclass,ChildClass,OtherChild.
MainClass()
{
ChildClass cc = new ChildClass();
OtherChild oc = new OtherChild();
//Set the name property of childclass
string childName = "some name";
}
ChildClass()
{
public string name {get; set;}
}
OtherChild()
{
//Here i want to get the name property from ChildClass()
//Doing this will make a new instance of ChildClass, which will not have the name property set.
ChildClass cc = new ChildClass();
}
Run Code Online (Sandbox Code Playgroud)
这是什么解决方案?