我有一个Provider,用于根据环境设置一些配置。
TestProvider.bar
})();
我可以访问共享配置对象:setFoo
在控制器或runblock中正常工作。
但是我很难在Config模块中调用-(NSArray *)getLinesArrayOfStringInLabel:(UILabel *)label
{
NSString *text = [label text];
UIFont *font = [label font];
CGRect rect = [label bounds];
CTFontRef myFont = CTFontCreateWithName((__bridge CFStringRef)([font fontName]), [font pointSize], NULL);
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
[attStr addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)myFont range:NSMakeRange(0, attStr.length)];
CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)attStr);
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, CGRectMake(0,0,rect.size.width,100000));
CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), path, NULL);
NSArray *lines = (__bridge NSArray *)CTFrameGetLines(frame);
NSMutableArray *linesArray = [[NSMutableArray alloc]init];
for (id line in lines)
{
CTLineRef lineRef = (__bridge CTLineRef )line;
CFRange lineRange = CTLineGetStringRange(lineRef);
NSRange range = NSMakeRange(lineRange.location, lineRange.length);
NSString *lineString = [text substringWithRange:range];
[linesArray addObject:lineString];
}
return (NSArray *)linesArray;
}
:它抱怨提供者是未知的。我错过了什么?
JSFiddle here。
答案 0 :(得分:0)
Angular追加"提供商"自动注入参考。这个corrected JSFiddle工作正常。
这是模块:
(function () {
angular.module('fooApp').config(['TestProviderProvider', testConfig]);
function testConfig (TestProviderProvider) {
console.log('Setting up the context!')
TestProviderProvider.setFoo({
'bar' : '654321'
});
}
})();