初学angularJS 个人总结 & 错误排除

本文总结了初学者在学习AngularJS时遇到的常见问题,包括VS中出现的“无效字符”错误,该错误由于Angular-csp.css被误识别为js导致,解决方法是将其移到Content文件夹;另外,还提到了两个JS错误,一个是语法错误,通过在'enron'后面添加', [ ]'来解决,另一个是直接删除routeParams以修复问题。" 53940894,5635958,SurfaceView崩溃解析与解决策略,"['Android开发', 'Android基础知识', 'UI编程', 'SurfaceView']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

------------ *  个人总结 * ------------
主要参考物:
和 勇哥的 DpMngWebsite

------------ *  错误排除 * ------------
C#:
public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/AngularJs").Include(
                "~/Scripts/angular.js", "~/Scripts/angular*")); 

Aspx:

<html lang="en" ng-app="enron">
<head runat="server">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title><%: Page.Title %></title>
    
    <asp:PlaceHolder runat="server">
        <%: Scripts.Render("~/bundles/AngularJs") %>
        <%: Scripts.Render("~/bundles/modernizr") %>
    </asp:PlaceHolder>

错误:VS蹦出错误:“无效的字符” 并且显示Angular-csp.css

解决:学习了http://stackoverflow.com/questions/26916671/angular-csp-css-breaking-in-chrome-extension之后,将angular-csp.css移出了Scripts的文件夹,并放入了Content文件夹。有错误是因为CSS文件被VS当成js读了。

------------------------------------

JS:

angular.module('enron').controller('NameListController', ['$rootScope', '$scope', '$routeParams', '$http', function ($rootScope, $scope, $routeParams, $http) {
    $scope.sayhello = function () {
        alert('hello'); return;
    }
}]);

错误:

Angularjs module isn't loading correctly

解决:在 'enron' 后面加 ', [ ] '

angular.module('enron',[]).controller('NameListController', ['$rootScope', '$scope', '$http', function ($rootScope, $scope, $http) {
    $scope.sayhello = function () {
        alert('hello'); return;
    }
}]);

------------------------------------

JS:

angular.module('enron',[]).controller('NameListController', ['$rootScope', '$scope', '$routeParams', '$http', function ($rootScope, $scope, $routeParams, $http) {
    $scope.sayhello = function () {
        alert('hello'); return;
    }
}]);

错误:

Error: [$injector:unpr] Unknown provider: routeParamsProvider <- routeParams

解决:直接删除 routeParams

angular.module('enron',[]).controller('NameListController', ['$rootScope', '$scope', '$http', function ($rootScope, $scope, $http) {
    $scope.sayhello = function () {
        alert('hello'); return;
    }
}]);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值