在这个小提琴中,我试图通过将文本传递给服务来格式化文本但是没有调用该服务:
http://jsfiddle.net/7MhLd/1038/
代码:
<div ng-controller="MyCtrl">
<div ng-repeat="line in lines">
<div class="preview">{{parseText(line.text)}}</div>
</div>
</div>
var myApp = angular.module('myApp', []);
myApp.factory('parseText', function(data) {
return "textParsed"
});
function MyCtrl($scope) {
$scope.lines = [{
text: 'res1'},
{
text: 'res2'}];
}
我正在返回textParsed
以显示未调用服务 - div中没有显示任何文本。如何调用此服务&amp;传递参数line.text
?
答案 0 :(得分:2)
在创建应用时,您犯了一些错误。
class Program
{
static void Main(string[] args)
{
using (MyContext ctx = new MyContext())
{
City c = new City() { Id2 = 32767 };
ctx.Set<City>().AddOrUpdate(c);
Person p = new Person() { Id2 = 32767 };
p.City = c;
ctx.Set<Person>().AddOrUpdate(p);
ctx.SaveChanges();
}
}
}
class City
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public int Id2 { get; set; }
}
class Person
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public int Id2 { get; set; }
public int CityId { get; set; }
public int CityId2 { get; set; }
public City City { get; set; }
}
internal sealed class CityConfiguration : EntityTypeConfiguration<City>
{
public CityConfiguration()
{
HasKey(t => new { t.Id, t.Id2 });
}
}
internal sealed class PersonConfiguration : EntityTypeConfiguration<Person>
{
public PersonConfiguration()
{
HasKey(t => new { t.Id, t.Id2 });
}
}
class MyContext : DbContext
{
public MyContext()
{
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<MyContext>());
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new CityConfiguration());
modelBuilder.Configurations.Add(new PersonConfiguration());
}
}
<强>标记强>
ng-app="myApp"
<强>代码强>
<div ng-app="myApp" ng-controller="MyCtrl">
<div ng-repeat="line in lines">
<div class="preview">{{parseText.parse(line.text)}}</div>
</div>
</div>