angularjs:表达式是不可赋值的

时间:2015-03-13 13:41:22

标签: angularjs angularjs-directive

我正在使用ui-gmap-google-map,我在其中定义了类似的坐标:

<div ui-gmap-google-map my-google-maps center='{  latitude: 51.4994961, longitude: -0.1246853 }' zoom="12">

这会引发错误:

Expression '{  latitude: 51.4994961, longitude: -0.1246853 }' used with directive 'uiGmapGoogleMap' is non-assignable!

其他人报告了相同的问题和明显的解决方案https://github.com/angular-ui/angular-google-maps/issues/418,但是如何使用ng-init来定义用于初始化指令的范围属性的对象?据我所知,我必须在设置scope.center之前将字符串过滤为json解析?

1 个答案:

答案 0 :(得分:2)

好的,对不起,我没有想清楚,但我找到了怎么做。方法如下:

<div ui-gmap-google-map center='center' ng-init="center = {  latitude: 51.4994961, longitude: -0.1246853 }">