AngularJS Php文件中的angular在$http之后不起作用


AngularJS Php file with angular in it not working after $http

我有一个php文件,里面有很多棱角分明的东西,当我直接包含它时,它可以很好地工作,但一旦我通过$http包含该php文件,如下所示:

$http.get('include/step'+step+'.php').
success(function(data, status, headers, config) {
    $("#tab_"+step).html(data);
});

它停止工作,然后我可以看到:{{category.title}}等内容显示为文本,而不是获取其值。

我从angular开始,我试图让angular识别通过ajax响应或$http响应添加的代码。

我也试过做

但我得到了这个棱角分明的bootstrap(数据);

Error: [ng:areq] Argument 'eventCatCtrl' is not a function, got undefined

eventCatCtrl是通过$http生成的文件中的第一个控制器。

我也做了这个有角度的.引导程序(数据,['eventApp']);eventApp是我主要模块的名称。仅供参考,所有这些http内容都是在div中完成的,如果重要的话,我已经在body上定义了我的模块。

应要求提供更多代码:

功能由此触发:

<div class="form-group progress-tracker__buttons" ng-controller="StepChange">
    <input type="button" class="btn btn-primary btn-save" value="Save">
    <input type="button" class="btn btn-default btn-next disabled" value="Next" ng-click="changeStep($event)">
    <div class="last-saved">Last saved: Not saved yet</div>
</div>

这是我的模块、控制器和功能:

var eventApp = angular.module('eventApp', []);
eventApp.controller('StepChange', function($scope, $http){
    $scope.changeStep = function($event){
        $http.get('include/step2.php').
        success(function(data, status, headers, config) {
            $("#tab_2").html(data);
        });
    };
});

在我的step2.php文件中,我有以下部分:

<div class="panel-group form-group sortable" id="catAccordion" ng-controller="eventCatCtrl">
    <div ng-repeat="category in categories.list">
        <p>{{category.title}}</p>
    </div>
</div>

我有一家这样的工厂:

eventApp.factory('EventCategories', function () {
    var EventCategories = {};
    EventCategories.list = [
        {
            name: "Robert Downey Jr.",
            character: "Tony Stark / Iron Man"
        },
        {
            name: "Chris Evans",
            character: "Steve Rogers / Captain America"
        }
    ];
    return EventCategories;
});

我有一个像这样的控制器为工厂:

eventApp.controller("eventCatCtrl", function($scope, EventCategories){
    $scope.categories = EventCategories;
});

在angular启动后,您无法初始化控制器。因此,您收到错误

Error: [ng:areq] Argument 'eventCatCtrl' is not a function, got undefined

此外,$http.get应用于保存/获取数据。为了包含其他布局和UI,您应该使用模板和指令。您将能够使用$scope中的变量来控制嵌入html内容的显示。

Angular中的延迟加载

http://ify.io/lazy-loading-in-angularjs/

此外,您还必须公开控制器注册服务,如下所示:

eventApp.config(['$controllerProvider', function($controllerProvider) {
    eventApp.controllerProvider = $controllerProvider;
}]);

并且,在您注册控制器的地方,使用以下内容:

eventApp.controllerProvider("eventCatCtrl", function($scope, EventCategories){
    $scope.categories = EventCategories;
 });