[英]My page turns blank when I try to use a controller in angular
I have a problem with angular to integrate a controller to my page. 我在将控制器集成到我的页面时遇到了问题。 The page becomes blank as soon as I try to integrate it. 我尝试将其集成后,该页面将变为空白。
<div class="container-fluid" ng-app="ods-widgets" ng-controller="myCtrl" >
<ods-dataset-context context="cont" cont-domain="https://data.rennesmetropole.fr" cont-dataset="{{dataset}}">
</ods-dataset-context>
</div>
<script>
var app = angular.module("ods-widgets", []);
app.controller("myCtrl", function($scope) {
$scope.dataset= "statistiques-de-frequentation-du-site-rennes-metropole-en-acces-libre";
});
</script>
Without the controller: http://jsfiddle.net/5c0xr8f4/13/ 没有控制器: http : //jsfiddle.net/5c0xr8f4/13/
With the controller: http://jsfiddle.net/8796ueyL/ 使用控制器: http : //jsfiddle.net/8796ueyL/
ods-dataset-context
is a component ( https://github.com/opendatasoft/ods-widgets ). ods-dataset-context
是一个组件( https://github.com/opendatasoft/ods-widgets )。 it's a component that I import via CDN. 这是我通过CDN导入的组件。
I just want to control what is inside the cont-dataset
我只想控制cont-dataset
I looked into the library that you mentioned in your comment. 我调查了您在评论中提到的图书馆。 It seems that the issue is that ods-widgets
is already an angular module that is being imported via the CDN. 似乎问题在于ods-widgets
已经是通过CDN导入的angular模块。 If you name your own angular module with the same name, you are effectively overwriting this existing module that you have imported. 如果使用相同的名称命名自己的角度模块,则实际上将覆盖已导入的现有模块。 So what you want to do is declare your own angular module and import ods-widgets as a dependency . 因此,您要做的就是声明自己的angular模块并导入ods-widgets作为依赖项 。 You can take a look at the Fiddle for a working sample, but the important part is this one: 您可以查看小提琴作为工作示例,但重要的是这一部分:
angular.module("myApp", ['ods-widgets']);
And in your HTML update the ng-app reference: 然后在您的HTML中更新ng-app参考:
<div class="container-fluid" ng-app="myApp" ng-controller="myCtrl" >
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.