简体   繁体   English

当我尝试以角度使用控制器时,我的页面变成空白

[英]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.

相关问题 当我在控制器中使用ui.bootstrap时,Angular会显示空白页 - Angular gives blank page when i use ui.bootstrap in my controller 使用导航栏时,所有PHP都变为未定义 - All PHP turns to undefined when i use my navigation bar 当我尝试从另一个组件导入时反应空白页面 - React blank page when I try to import from another component 当我尝试在这个项目中使用 input.value 取平均值时出现问题。 无论我输入什么,Avarege 都会变为“0” - There is a problem when i try to use input.value for taking average in this project. Avarege turns '0' whatever I enter to inputs 当我尝试在反应中使用路线广告路线时,我的页面不断消失 - my page keeps disappearing when I try to use routes ad route in reacts $ locationprovider.html5mode刷新页面时会关闭CSS - $locationprovider.html5mode turns off my css when I refresh page 当我尝试刷新页面时出现此错误 - When i try to refresh my page i have this error 我使用以下方法在新选项卡中显示页面,但是当我使用 target="_blank" 时,我的参数丢失了 - I use the following approach to display the page in a new tab, But when I am using target=“_blank” , my params were lost 当我尝试编译我的 React 应用程序时,出现空白屏幕 - When I try to compile my React app I get a blank screen 运行代码时浏览器显示空白页 - Browser displaying blank page when I run my code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM