我是AngularJs的新手,并且在尝试使用依赖项测试指令时遇到问题(虽然指令本身按预期工作).我无法在这里或其他资源上找到任何答案.
这是我的代码:
指示:
angular.module('MyApp')
.directive('appVersion', ['config', function (config) {
return function (scope, elm) {
elm.text(config.version);
};
}]);
Run Code Online (Sandbox Code Playgroud)
服务(价值):
angular.module('MyApp')
.value('config', {
version: '0.1'
});
Run Code Online (Sandbox Code Playgroud)
测试:
describe('Directive: AppVersion', function () {
beforeEach(module('MyApp'));
var element;
it('should have element text set to config value', inject(function ($rootScope, $compile, config) {
var scope = $rootScope;
element = $compile('<app-version></app-version>')(scope);
expect(element.text()).toBe(config.version);
}));
});
Run Code Online (Sandbox Code Playgroud)
我的测试失败并显示消息:
Error: Expected '' to be '0.1'.
Run Code Online (Sandbox Code Playgroud)
意味着配置值被正确注入,但$ complile没有使用它.我真的很感激任何帮助.谢谢.
我试图通过Intent.putExtras这样的方式将数据从一个活动传递到另一个活动:
private ArrayList<HashMap<String, String>> mGroups = new ArrayList<HashMap<String, String>>();
private ArrayList<HashMap<String, String>> mUsers = new ArrayList<HashMap<String, String>>();
...
Bundle data = new Bundle();
data.putInt("mode", mode);
data.putSerializable("groups", (Serializable) mGroups);
data.putSerializable("users", (Serializable) mUsers);
data.putInt("current_class", mCurrentClassId);
data.putInt("current_user", mCurrentUserId);
Intent intent = new Intent(ctx, ChildActivity.class);
intent.putExtras(data);
ctx.startActivityForResult(intent, 0);
Run Code Online (Sandbox Code Playgroud)
这mUsers是一个HashMap<String,String>包含用户数据的列表,包括Base64编码的照片,此列表中的字符串大小总和约为500Kb
startActivityForResult用黑屏调用挂起几分钟然后我得到ANR错误.onCreate根本没有调用子活动.
如果我不在mUsers中添加大字符串(没有Base64编码的照片) - 工作得很好.
请帮忙.