为什么在为Chrome应用程序编码时无法在routeProvider中使用controllerAs语法?

Angellica.araujo

角版本:1.4.9

你好,

我正在打包一个用John Papa代码风格编写的有角度的Web应用程序。但是我一直在面对基本问题。其中之一是设置routeProvider。我想在控制器文件中配置它,但似乎无法正常工作。当我直接在模块配置中配置它时,它不接受controllerAs作为语法...

在mycontroller.js文件上

// Has no effect
angular.module('myDearModule').
controller('MyController', MyControllerFn).
config(function($routeProvider) {
    $routeProvider.when('/page', {
       templateUrl: 'tpl.html',
       controller: 'MyController',
       controllerAs: 'mycontrollerVm'
    });
});

function MyControllerFn() {
....

现在,如果我在加载所有内容后尝试使用一种module.routing.js文件

// After setting up module and controller
angular.module('myDearModule').
config(function($routeProvider) {
    $routeProvider.when('/page', {
       templateUrl: 'tpl.html',
       controller: 'MyController',
       controllerAs: 'mycontrollerVm'
    });
});

无效...我也收到此错误:[ng:areq]参数'MyController'不是一个函数。有未定义

我尝试使用以下建议在视图之间进行切换:对打包的应用程序使用angular $ routeProvider

指令和路由工作正常,但未设置控制器:(

当我在视图中使用ngController语法时,会发生相同的错误。

我需要使用路由来保持此网络正常工作。我是在做错什么,还是没有办法?有人可以给我展示Chrome应用程序中controllerAs的示例吗?我仅找到简单的示例(根本没有路由或页面更改)。

亚历克斯·萨博(AlexSzabó)

'MyController' is not a function. Got undefined

可能意味着您的控制器中存在语法错误。加载控制器,过滤器等时,不应有任何错误消息。如果发现任何错误并进行纠正,controllerAs则应可以正常工作。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么在控制台购买时无法在我的应用程序中使用此功能?

为什么我无法在Wpf中使用应用程序内的WebView来导航html文件?

为什么我的字体无法在ASP.NET Core MVC应用程序中使用?

在控制台应用程序中使用async / await时,为什么需要AsyncContext?

在控制台应用程序中使用CommonOpenFileDialog时,为什么会出现此异常?

在AngualrJS中使用controllerAs时为什么没有输出

为什么在Android应用程序中使用jdbc是错误的?

为什么要使用controllerAs语法

为什么图像在 Android Studio 中使用我的应用程序打开但安装在我的手机上时它们挂起或无法打开?

为什么Flutter应用程序无法在chrome上使用命令flutter run -d chrome运行

为什么使用Promises的节点应用程序无法返回?

为什么基于Firebase的应用程序在伊朗无法使用?

当我仅运行一个应用程序(chrome)时,为什么系统会使用2 GB的内存?

为什么当我尝试在celery任务中使用模型时django引发“尚未加载应用程序”错误?

为什么我在 Python 中使用快捷方式时我的应用程序一直打开?

为什么我的 .NET Web API 应用程序在使用 docker-compose 时无法连接到 docker 上的 MySQL?

如何在wsgi应用程序中使用gzip编码?

为什么下载依赖时我的flutter应用程序无法编译?

为什么导入后运行Docker镜像时无法启动应用程序

为什么此Java应用程序无法在刷新时显示JSON数据?

无法理解为什么在运行以下代码时应用程序崩溃

为什么在 React 应用程序中使用 @import 来使用谷歌字体?

为什么不应在 Windows 特定应用程序中使用“系统”

为什么在 Canvas 的绘制应用程序中使用 beginPath 方法?

为什么在我的 web 应用程序中使用 Tomcat 会出现 Class NotFound 异常?

为什么我不能在 Angular 应用程序中使用 JS 文件?

为什么我们不在NodeJS应用程序中使用“ express.use”?

为什么在Android Studio中使用教程应用程序会得到“不受支持的Gradle版本”?

为什么在GWT(或任何Web应用程序)中使用命令模式?